-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Description
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
The method that's used to en-queue a state change is labelled as setState -- semantically meaning set the state (implicitly usually wrongly understood as, now).
What is the expected behavior?
Perhaps, I'm taking a hard stance on semantics, and will probably get some controversy to this as well, but I believe the current method as setState should actually be treated as a bug in the API naming. I think it should be renamed as enqueueState, or queueState, or pushState, or something on those lines. Perhaps, someone else can come up with a nicer name?
I've seen even people quite experienced in React to make the rookie mistake now and then, of doing setState like it's a synchronous function, and then go bug-hunting. I'm guilty of it as well in deeply nested contexts where its not always obvious. And now with React Fiber, I think it's all the more important to stay relevant.
Let's just bite the bullet, and do a breaking change please. Lifecycle method deprecations are quite of the same magnitude, but it was done - And I for one would think this has to be done. It's not so hard for people to do a Find & Replace - In fact, I'm sure some beginners would even end up fixing some undiscovered errors while doing so, because of a breaking change.
Pros
- All good things.
Cons
- Make some people hold a grudge against me, because they had a function called
queueState(or whatever) in their application logic and now they painstakingly have to change that too cursing me, rearranging logic. - Extremely large organisations like Facebook is going to have to spend some time with unmaintained projects. (I'm still not sure if this is a con, because it would make the code expresses itself more clearly for newcomers who would be less prone to mistakes because of it).
- You have to type 2 extra characters (Strike this if you're sane and use auto-complete).
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
<=17 so far.