React: setState(DOESN'T)
I'm an old Java programmer. If I see x.foo and x.setFoo(y), then I expect x's new foo to be y.
So in my linguistic world, Component.setState(x) really does an "updateState", or something, and it would have saved me some time if they had used a different name. :-)
Now I understand that the argument is really more like a delta. It only specifies that parts that are different.
Also React starts with a shallow comparison between the existing state and the argument to setState(...). So, if I don't compose setState's argument correctly, there can still be differences that React will not find.
I need to dig into this more. However, I'm learning Redux now, which does it's own setState(...), so I might not get back to this for awhile.
So in my linguistic world, Component.setState(x) really does an "updateState", or something, and it would have saved me some time if they had used a different name. :-)
Now I understand that the argument is really more like a delta. It only specifies that parts that are different.
Also React starts with a shallow comparison between the existing state and the argument to setState(...). So, if I don't compose setState's argument correctly, there can still be differences that React will not find.
I need to dig into this more. However, I'm learning Redux now, which does it's own setState(...), so I might not get back to this for awhile.
Comments
Post a Comment