Does passing an object via props to child react component, clone the original object or pass by reference?

后端 未结 3 513
感动是毒
感动是毒 2021-01-17 11:56

If am to pass an object to a child component via the components props, does this object get cloned or does it simply pass a reference to the original object?

For exa

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 12:53

    Props reference to objects, in fact you can pass methods with context. Mutating props is a very bad pratice discouraged by almost every linter, when you want to mutate data coming from props is better to deep clone prop and work on cloned data.

提交回复
热议问题