React this.props.children versus createReactClass

142 Views Asked by At

I have the following code that works:

    let registered = [];
    React.Children.forEach(this.props.children, (child) => {
        let name = child.type.name;
        if (registered.indexOf(name) === -1) {
            gLayout.registerComponent(name, createReactClass({
                render: () => (child)
            }));
            registered.push(name);
        }
    });

However, my question is if I can provide the child directly without wrapping it into a new react class.

I tried replacing the createReactComponent with render function, with simply child.type and React.cloneElement(child, {}) but none of them work because the registerComponent function (of golden-layout framework) will complain that either a constructor function or the componentWillUpdate member function is missing.

Wrapping a new component around an existing component seems unnecessary overhead and may require me to duplicate code, so I'm looking for a cleaner option.

0

There are 0 best solutions below