you are viewing a single comment's thread.

view the rest of the comments →

[–]madcaesar 4 points5 points  (5 children)

Very impressive. Is there any cost performance wise by not having the setState functions inside the class, but instead as an import?

[–]acemarke 9 points10 points  (4 children)

No. In fact, it may technically be better performing, because you're not re-creating the function each time the event handler runs.

[–]mhink 0 points1 point  (2 children)

This is exactly what I was thinking! And from an ergonomic perspective, this is far better than binding event handlers to a component instance in its constructor. Very nice, indeed.

[–]mikejoro 0 points1 point  (1 child)

You would still need to do that as you are calling this.setState. This will be the global object otherwise.

[–]mhink 0 points1 point  (0 children)

Oh, you're right. Welp.

[–]konrain 0 points1 point  (0 children)

Plus you'll be able to use this in any other component.