1

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.

Dan
  • 1,518
  • 5
  • 20
  • 48

1 Answers1

2

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} />;
skyboyer
  • 22,209
  • 7
  • 57
  • 64