import produce from 'immer'
const object = {
a: {
b: 1,
target: 2,
},
c: 3,
d: 4,
}
const newObject = produce(object, (draft) => {
delete draft.a.target
})
console.log(object)
// => { a: { b: 1, target: 2 }, c: 3, d: 4 }
console.log(newObject)
// => { a: { b: 1 }, c: 3, d: 4 }
More than 1 year has passed since last update.
JavaScript で Immer を使ってオブジェクトの階層が深いキーを immutable に消す(変更する)
Last updated at Posted at 2023-01-16
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme