You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
I wrote a class that when inherited allows creating component in an ES6 fashion. This class triggers different parts of Radium.wrap during its lifecycle, so it's quite dirty but here it is :
import{Component}from'react';import{wrap}from'radium';classRadiumComponentextendsComponent{constructor(props,opts){super(props,opts);if(this.state){this.state._radiumStyleState={};}else{this.state={_radiumStyleState: {}};}}componentWillUnmount(){super.componentWillUnmount();if(this._radiumMouseUpListener){this._radiumMouseUpListener.remove();}if(this._radiumMediaQueryListenersByQuery){Object.keys(this._radiumMediaQueryListenersByQuery).forEach(function(query){this._radiumMediaQueryListenersByQuery[query].remove();},this);}}renderWithStyles(){console.error("renderWithStyles should be defined by your component");returnnull;}render(){varrenderedElement=this.renderWithStyles();returnwrap({render: ()=>renderedElement}).render();}}exportdefaultRadiumComponent;
Your component just needs to implement a renderWithStyles method.
I'm not doing a PR as this is clearly a draft, and I don't know if you're interested in this in the short-term.
Including it in the project would allow for a cleaner implementation, since hacky calls to wrap would not be needed anymore.
Moreover, I don't know if classes and modules works well with JSX-loader.
The text was updated successfully, but these errors were encountered:
fredericlb
changed the title
Radium in ES6 components
Using Radium with ES6 components
Apr 28, 2015
Yes, I like where this is going. I am planning to convert nuclearmail to ES6 classes soon, and I'll probably have a PR for Radium then. I am thinking of moving most of the wrap functionality into a separate helper, and then having the wrap and ES6 versions use the same code. We could either have a special base class, like RadiumComponent, or use the enhancer pattern, like this: https://github.com/nmn/react-observe/blob/master/src/index.js.
I think @vjeux outlined some other options, I can't recall them now, so there may be something even better.
Hi,
I wrote a class that when inherited allows creating component in an ES6 fashion. This class triggers different parts of Radium.wrap during its lifecycle, so it's quite dirty but here it is :
Your component just needs to implement a renderWithStyles method.
I'm not doing a PR as this is clearly a draft, and I don't know if you're interested in this in the short-term.
Including it in the project would allow for a cleaner implementation, since hacky calls to wrap would not be needed anymore.
Moreover, I don't know if classes and modules works well with JSX-loader.
The text was updated successfully, but these errors were encountered: