Skip to content

React Native wrapper for setState to prevent state manipulation on unmounted components.

Notifications You must be signed in to change notification settings

KamranFekri/safe-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

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.

About

React Native wrapper for setState to prevent state manipulation on unmounted components.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published