ac3-state-management-examples
ac3-state-management-examples copied to clipboard
Looking for example with remote data combined with local data
A good real world 'use case' would be a shopping cart. below is a typical result object for a shopping cart. The goal here is to set a local variable called "user_selected_qantity" with the shopping cart remote data. and initialize a default value for it. here user should be able to increment and decrement "user_selected_qantity" for the given product. becuase evertime a user increments qty for the product it should not have to go to the server right. I hope i'm explaining this correctly
{
"data": [
{
"id": 1,
"__typename": "shoppingCart",
"userId": 33,
"productId": 25,
"productName": "some name",
"stock": 23,
"price": 50,
"user_selected_qantity": 23 <-------- Local Field,
"is_slected": true <-------- Local Field
}
...
]
}
This can be achieved seamlessly using two ways.
1- putting the data in to the component "state" and manipulating it. 2- putting the data in to "Redux or other state management library" and manipulate it.
By doing so. aren't we not duplicating the data? one in the redux and one in the cache. should I have to update both? I was hoping to know the best practice for this use-case using ApolloV3 stuff.