Timeline for Display toast after action
Current License: CC BY-SA 4.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 6, 2020 at 15:26 | comment | added | Drew Reese | @PeterBoomsma (2) Yes, when your application loads (page refresh or native app opens) it can read the persisted app state from local storage and populate the application state. Here your app state is acting as cache. | |
Aug 6, 2020 at 15:23 | comment | added | Drew Reese | @PeterBoomsma Thank you. (1) Separating the state persistence to localStorage is an effect of updating state, i.e. state updated -> persist to longer-term storage. I'm a fan of the Single Responsibility Principle where basically each module/class/function is responsible for a single aspect of the overall functionality of the program. In a bigger system like redux I'd just have a piece of middleware or handler that simply every second or so writes app state to local storage, removing the responsibility from the UI code. | |
Aug 6, 2020 at 10:14 | comment | added | Peter Boomsma |
Thanks again Drew. I love this line setMovies((movies) => sortMovieList([...movies, movie])); very clear and concise. I also like the removal of the ternary statement and make the snackBar output part of the code. Makes it much more readable. 2 questions, if you don't mind: 1. why prefer the useEffect to put the movie in localStorage over the addMovie function. 2. It feels duplicate, placing a movie object in the movies state and also in the local storage. I have 2 places where movies are stored, is there a method where the localStorage acts as the point of truth?
|
|
Aug 6, 2020 at 10:03 | vote | accept | Peter Boomsma | ||
Aug 5, 2020 at 21:37 | history | answered | Drew Reese | CC BY-SA 4.0 |