Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 23, 2019 22:31
Show Gist options
  • Save jsmanifest/75c4d085def7eaa8dcb6fef5a8d10d79 to your computer and use it in GitHub Desktop.
Save jsmanifest/75c4d085def7eaa8dcb6fef5a8d10d79 to your computer and use it in GitHub Desktop.
const insertToHistory = (state) => {
if (state && Array.isArray(state.history)) {
// Do not mutate
const newHistory = [...state.history]
newHistory.push(state)
return newHistory
}
console.warn(
'WARNING! The state was attempting capture but something went wrong. Please check if the state is controlled correctly.',
)
return state.history || []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment