2 ms·
I prefer to use POJO (plain old JavaScript objects).
by petilon 4y ago
I 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.