1

Say I have a state slice that looks like the following:

{
    "ids":[20,23,32,60,101],
    "entities":{
        "20":{
            "id":20,
            "name":"Actor",
            "questions":[{
                "id":20,
                "role_id":20,
                "field_type":"text",
                "field_name":"Height",
                "field_default_value":null,
                "field_validation_rules":"required,string,max:5",
                "answers":[{
                    "id":1,
                    "question_id":20,
                    "value":"Testing",
                    "created_at":"2019-07-30T13:20:09.000000Z",
                    "updated_at":"2019-07-30T13:20:10.000000Z"
                }]
            }],
            "created_at":"2019-07-24T13:35:33.000000Z",
            "updated_at":"2019-07-24T13:35:33.000000Z",
        }
    },
    "allUserRolesLoaded":true
}

How would I go about updating that answer in my reducer, I was thinking that I would be able to use something like the following, but when trying to drill down into the questions and then answers I get all kinds of problems.

adapter.updateOne(
{
  id: 2,
  changes: {...state.entities[2], likes: value}
},
state
);

Now, I know that this should probably be normalised in someway, and usually I would, however, this isn't an option at this stage.

ChrisBratherton
  • 1,540
  • 6
  • 26
  • 63
  • I would suggest you to re-structure your json, looks very deep and complex. One of the keys using redux is to simplicity – Umesh Aug 02 '19 at 04:24
  • Yes, I understand this, and usually I would however, I working with some legacy stuff with numerous parties. Making changes to the general structure of the app is not really an option. – ChrisBratherton Aug 02 '19 at 09:04

0 Answers0