A minimal, immutable, deep set utility for Javascript objects and arrays.
Inspired by, and based on, NickGard's tiny-get
import { set } from 'tiny-immutable-set';
const newState = set(state, 'deep.path', newValue);
The original state
is not modified.
-
If you're using lodash then you don't need this: see this thread for alternatives.
-
The small bundle size of this library comes with a slight speed tradeoff. This library is a little slower than immutable-assign and immutable.js, but a little faster than Immer and seamless-immutable. It's faster if you use a string path instead of an array of path parts. See full benchmark here.