Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
quick'n'dirty state replacement that emulates the general behaviour of the old setState
// 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
You can’t perform that action at this time.