airbnb/react-with-styles

How can I return a react component using withStyles?

danvc opened this issue · 2 comments

danvc commented

Hi everyone.

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.

That snippet needs a slight tweak - withStyles takes a component, not an element.

danvc commented

The right solution:

let MyComponent = (withStyles(this.props.style)(Component));

and then call it and pass the properties down like:
return <MyComponent {...anyProps}/>

Thanks @ljharb