Posts

Showing posts with the label redux

Fetch again, or set state? - react, redux

This is the question which always confuse me, so i decided that i'm asking you. What i mean is that i have a Node server, and an SQL database in the backend, and a redux store on the frontend. The main component fetches every time it did mount, processes the response, and dispatch it to the store. All what the user see depending on the store. So if a change happens, it gets uploaded to the database through the server, but if this change happens on the main component's child component, the state isn't gets uploaded to the store because the main component isn't do mount. Let me show what i mean: The above code just an illustration what i mean. Obviously the second solution looks better, but in my code's state i need to loop through 3 arrays to find the target element. But the amount of items are unknown both in the database, and both in the state. If i get the items from the database it gets processed with 2 maps, and then a sort. If i want to search the target item, ...