LocalStorage and useEffect

In a typical CRUD scenario, one would be using the above mentioned like this:
• useEffect => On load: check if localStorage data exists, then parse it and save in state.
• useEffect => Listens for changes in state data, then saves it to localStorage.

How can I prevent the second
useEffect
from running after the first on initial load?

Let's say I have already added some data in localStorage. When my app loads, it fetches said data and calls setState to save it in my local state. Since this data is in the dependency array of the second
useEffect
, it triggers it, saving nothing.

Thanks!
Was this page helpful?