3 ms·
Try going all in on persistent data structures. I haven't tried this one but perhaps it will do the trick: https://github.com/cronokirby/persistent-ts https://
by mrkeen 4y ago
Try going all in on persistent data structures. I haven't tried this one but perhaps it will do the trick: https://github.com/cronokirby/persistent-ts https://github.com/cronokirby/persistent-ts
- petilon 4y agoI prefer to use POJO (plain old JavaScript objects).
- phailhaus 4y agoYou only need to update the objects that actually changed, and only along the path of the keys that changed. Deep cloning is overkill because you'll incur way too many updates. For example: const [largeArray, setLargeArray] = useState<MyObj[]>([]); const updateObject = (index: number) => (newObj: MyObj) => { setLargeArray(prevArray => ([ ...prevArray.slice(0, index), newObj, ...prevArray.slice(index+1), ])); }
- mrkeen 4y agoAnd if you don't want to write it yourself, use a library.