Using Prototypes in React State

I’m trying to use prototypes to make looking up data from a deeply nested object easier. The issue is, when I use lodash’s cloneDeep function the prototype chain is broken ( I’m pretty sure ). I’m using the cloneDeep function to make sure not to mutate the state directly.

Before waisting anyone’s time with some of the code from the project, is this an okay practice? Is it correct to do something the following or should prototypes be avoided when storing objects in state?

const parent = { a: { b: { c: null }}}
const child = Object.create(parent)
parent.a.b.c = child

this.setState({ parent }) 

Thank you in advance for the help 🙂

138 thoughts on “Using Prototypes in React State”

  1. I’m amazed, I have to admit. Seldom do I encounter a
    blog that’s both equally educative and entertaining, and let me tell you, you have hit the nail on the head.
    The problem is something that too few people are speaking intelligently about.

    I am very happy I came across this during my search for something concerning this.

    Reply
  2. Usually I don’t learn article on blogs, however I wish to say
    that this write-up very forced me to check out and do it! Your writing taste has been amazed me.
    Thanks, quite great article.

    Reply
  3. Hey There. I discovered your weblog the use of msn. This is an extremely smartly written article.
    I’ll be sure to bookmark it and come back to read more of your helpful info.
    Thanks for the post. I’ll definitely return.

    Reply
  4. I’ve been exploring for a little for any high-quality articles or weblog posts on this sort of area .
    Exploring in Yahoo I finally stumbled upon this site. Studying this info
    So i am happy to exhibit that I have a very excellent uncanny feeling I discovered exactly what
    I needed. I such a lot undoubtedly will make certain to do not put
    out of your mind this site and provides it a look regularly.
    quest bars http://j.mp/3C2tkMR quest bars

    Reply

Leave a Comment