SoleCincis / tracker-App

a little React Native App able to track expenses
0 stars 0 forks source link

localStorage API #6

Open SoleCincis opened 4 years ago

SoleCincis commented 4 years ago

To persist data. There is a way to persist these values permanently since all I'm using a mock array to display and add new expenses. Using localStorage() API adds the functionality to save all the expenses that the user adds to the list.

The localStorage API allows me to access a Storage object that is the stored data saved across browser sessions.

Each expense value you are going to store in the localStorage API is going to be a string so make sure you understand the difference between JSON.stringify() and JSON.parse().

Replace the current mock ALL_EXPENSES .

SoleCincis commented 4 years ago

I had trouble saving data from state to storage.
I cannot update a value in the state and immediately work with the variable in the same context, setting state is for re-renderings and updating the state of a component, not for updating a variable one work with it = https://reactjs.org/docs/state-and-lifecycle.html#using-state-correctly

that's why I need to work with data itself, in my case updated expenses, which is than passed to state and store.

Screenshot 2020-04-15 at 17 47 34