Skip to content

Instantly share code, notes, and snippets.

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}
return [state, setLegacyState]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment