lundi 15 août 2016

Data structure for handling multiple checkboxes (React, Redux)

Given data in the following format (array of objects-leads): [{leadId: 123, some info, products:[{productId: 789, some info},{productId: 335, some info} ...}], ... }, etc].

Every product is a react component with checkbox. When I receive data I have to transform it to UI state (single object) that looks like this: {123: {789: true or false, 335: true or false}} for handling checkbox clicks. In the end I would like to have all checked products in the following format [{leadId: someId, productIds: [array of Ids of products]}, ...] therefore I transform UI state.

Workflow: input data -> transform to UI state and save it into the store -> (user works with UI and store changes) -> transform to output data -> send data. Is there a better data structure for handling checkbox clicks here? What about extending product objects with isChecked flag and put array into the store?

Thank you very much.




Aucun commentaire:

Enregistrer un commentaire