airbnb / react-with-styles

Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I return a react component using withStyles?

danvc opened this issue · comments

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.

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