Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
The question here is not about how to export, but, how to return a React object with the css injected?
I'm trying to achieve something like it:
return ( withStyles(this.props.style)(<Component {...params}/>) );
Where the intention is to return Component with all CSS set using withStyles and with its styles injected in the property called style.
withStyles
HOC takes class/function and returns decorated class/function. That's why we cannot pass there component instance(<Component {...params}>
creates/returns object under the hood).
Having this in mind and JSX's requirement to have component's name started from Capital letter we can do next:
const StyledComponent = withStyles(this.props.style)(Component);
return <StyledComponent {...params} />;
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.