H
H
hood522019-10-05 02:57:46
React
hood52, 2019-10-05 02:57:46

How to wrap a component in React?

Good day.
There is a component <Component prop={value} />.
There is some function that wraps it

const withWrapper = (ComponentToWrap) => {
    return <div className="Wrapper"><ComponentToWrap /></div>
}

However, when calling
import Main from ...
...

render() {
    return (
        { withWrapper(Main) }
    );
}

...
the proper result cannot be achieved, in the console the following message
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.


What is the problem and how can it be solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-10-05
@hood52

const withWrapper = (ComponentToWrap) => (props) => {
  return <div className="Wrapper"><ComponentToWrap {...props} /></div>;
};

render() {
  return (
    <WrappedMain />
  );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question