Last active
August 7, 2022 05:48
-
-
Save djD-REK/2eb6b333157b304c161f649855880726 to your computer and use it in GitHub Desktop.
This file contains 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
// Save search term state to React Hooks with spread operator and wrapper function | |
// Using .concat(), no wrapper function (not recommended) | |
setSearches(searches.concat(query)) | |
// Using .concat(), wrapper function (recommended) | |
setSearches(searches => searches.concat(query)) | |
// Spread operator, no wrapper function (not recommended) | |
setSearches([...searches, query]) | |
// Spread operator, wrapper function (recommended) | |
setSearches(searches => [...searches, query]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment