To update nested data with immutability helper, you usually hard-code the path to the data you want to update, sometimes with variables for keys. What do you do if the number of keys/indexes (that is, the depth of nesting) is also variable? I'm looking for a way to update data given an arbitrarily long list of keys. Given [0, 1, 1]
, I want to update data[0][1][1]
, or given [9]
, I'd like to update data[9]
.
Context: I have a deeply nested array of comments, where a nested comment is a reply to its parent, and I need to add/remove/edit comments based on which comment is selected.
It looks like Immutable.js has methods that work just like I'm describing:
Immutable.JS’s get() or getIn() methods … [access] properties via an array of strings, each of which represents a property key.
https://redux.js.org/recipes/using-immutablejs-with-redux#difficult-to-interoperate-with
Is there a good way to do this with immutability-helper? If not, it's not too late for me to switch to Immutable.js.