set value from another data when that is available 1

set value from another data when that is available

// when state updates use useEffect to update new variable / call fn
useEffect(() => {
    setNewData(myData);
}, [myData]);

Here is what the above code is Doing:
1. We’re creating a new variable called newData and setting it to the value of myData.
2. We’re using useEffect to call a function whenever myData updates.
3. The function we’re calling is setNewData, which updates the value of newData.

So, whenever myData updates, newData will also update.

Similar Posts