Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial previous value param to usePrevious hook #316

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wherehows
Copy link

@wherehows wherehows commented Jul 4, 2024

@@ -1023,7 +1023,7 @@ export function usePrevious(value) {
setCurrent(value);
}

return previous;
return previous || initialPreviousValue;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as default value, not the initial. Imagine calling usePrevious<number>(value, 1) with the value being: 1, 2, 0, 3. And we'll see 1, 1, 2, 1, right? It would be nice to have some tests confirming it works for some inputs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

default value for usePrevious hook
2 participants