-
Notifications
You must be signed in to change notification settings - Fork 208
Remove usages of unsafe lifecycle methods #406
Comments
Thanks! I don't have time to work on this now myself but I'd love a PR for it :) |
There is somebody working on this already? I would love to help here! |
I tried to start but hit #407. Feel free to pick it anyway |
Thank you, just started making the changes to import polyfill from "react-lifecycles-compat";
class ThemeProvider extends React.Component {
state = {
theme: null
};
static getDerivatedPropsFromState(nextProps, prevState) {
if (prevState.theme !== nextProps.theme) {
return { theme: nextProps.theme };
}
return null;
}
componentDidUpdate(prevProps, prevState) {
if (this.state.theme !== prevState.theme) {
this.publishTheme(this.state.theme);
}
}
UNSAFE_componentWillMount() {
// set broadcast state by merging outer theme with own
if (this.context[CHANNEL]) {
this.setOuterTheme(this.context[CHANNEL].getState());
}
this.broadcast = brcast(this.getTheme(this.props.theme));
}
//all the functions here still the same
}
polyfill(ThemeProvider)
export default ThemeProvider I ran npm test and all the test pass, is this approach okay? |
can the cWM be replaced with cDM or constructor? |
Maybe. I'll be honest and say that I only barely understand what's going on with this code. I'd actually prefer to rewrite this whole Theming system using the new context API (with |
Feel free to borrow ideas from #styled-components/styled-components#1664 Particularly, here's the solution for |
That's a good idea, |
I would like to work on this using @kentcdodds suggestion above regarding the theme-provider. |
This project is now in an unmaintained status. Please see the README for more information. |
React team recently published a blogpost: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html
TL;DR:
cWM
,cWRP
, andcWU
methods are considered unsafe for future async rendering and will be deprecated soon. The recommended way for open source maintainers to deal with it is to usereact-lifecycles-compat
package and migrate to newstatic getDerivedStateToProps
methodThe text was updated successfully, but these errors were encountered: