Append arr2 elements to arr: (8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
(arr) => arr.concat(gerArr2())
Append arr2 array to arr: (4) [Array(4), Array(4), Array(4), Array(4)]
(arr) => [...arr, gerArr2()]
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])
https://stackoverflow.com/questions/54676966/push-method-in-react-hooks-usestate
https://javascript.plainenglish.io/how-to-add-to-an-array-in-react-state-3d08ddb2e1dc
https://www.skptricks.com/2018/06/append-or-prepend-html-using-reactjs.html
No comments:
Post a Comment