LoginSignup
0
0

More than 1 year has passed since last update.

JavaScript で Immer を使ってオブジェクトの階層が深いキーを immutable に消す(変更する)

Last updated at Posted at 2023-01-16
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 }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0