Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Catching array change in React Hooks with useEffect

Look at the /src/App.js file...

When you just update state with a copy of “oldUncaught”, the reference is a same of the preview state.

When you use “oldCaught” inside spread operator, the new state is assigned to a new reference different from initial state.

In JS array are copied by reference, so if you don’t use spread operator, the reference doesn't change and useEffect can’t catch it. Voilà !

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages