safe-state
v1.0.4
Published
React Native wrapper for setState to prevent state manipulation on unmounted components.
Downloads
12
Maintainers
Readme
React Native wrapper for setState to prevent state manipulation on unmounted components.
How to use safe-state
//1. Import safe-state
import SafeState from 'safe-state';
//2. Initialize the safe-state object
this.setMountedState = SafeState(this)
//3. Use safe-state
this.setState({}) //instead of this
this.setMountedState({}) //use this
//Note: Lifecyle methods
componentDidMount(){...} //instead of this
componentDidMountSafely(){...} //use this
componentWillUnmount(){...} //instead of this
componentWillUnmountSafely(){...} //use this
A working react-native example can be found here.