Learn-React-In-30-Minutes icon indicating copy to clipboard operation
Learn-React-In-30-Minutes copied to clipboard

Changes to be made in App.js

Open SharathVaddireddy opened this issue 11 months ago • 0 comments

  1. the import of uuid should now say (according to their readme)

    import { v4 as uuidv4 } from 'uuid';

  2. There is a problem with the react.strictMode in that the code in de video doesn't restore the todos from storage correctly.

Although removing strictmode solves it, I also watched your react hooks video in which you explain how to correctly call the setState functions and why it otherwise doesn't do what you might expect when called more than once.

So it seems in this case the setTodos in the useEffect that initializes the todo's should say:

setTodos( prevTodos => [...prevTodos, ...storedTodos] );

instead of

setTodos(storedTodos)

After that change the function will restore the todos even in strictmode.

SharathVaddireddy avatar Mar 26 '24 00:03 SharathVaddireddy