Created
June 17, 2019 10:46
-
-
Save midudev/5ec4ff91df28bd75c2f7b6bbd7f7fc06 to your computer and use it in GitHub Desktop.
quick'n'dirty state replacement that emulates the general behaviour of the old setState
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hook to emulate legacy state behaviour | |
const useLegacyState = (initialState = {}) => { | |
const [state, setState] = useState(initialState) | |
function setLegacyState (partialNewState) { | |
let newState = {...state} | |
if (typeof partialNewState === 'object' && partialNewState !== null) { | |
newState = {...newState, ...partialNewState} | |
} | |
setState(newState) | |
} | |
return [state, setLegacyState] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment