Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


I prefer to use POJO (plain old JavaScript objects).


You 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),
        ]));
    }


And if you don't want to write it yourself, use a library.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: