0
vicary
5y

So for the special kind of event handlers that runs before an event, would you prefer the react style "will" as in "onWillChange", or the W3C style "before" as in "onbeforeunload"?

Comments
  • 6
    Before/after

    "Will" makes you wonder if it "will" actually do it.
  • 1
    @C0D4 hmm... that makes the idea way more clearer.

    React's render cycle and state update batching, by nature, schedules things to at least 1 tick away. That may confuses those thinking "before" as a synchronous before.

    So it should be "before" if it happens in the same tick, otherwise use "will".

    A good way to imply the possibility of cancellable events too.
  • 0
    "On will unmount" could always be just "on unmount", since it doesn't affect the component being unmounted, it's just a way to clenup things during that process.

    "On before unmount" on the other hand signifies the main proccess didn't start yet (unmounting has been requested and approved by preflight checks, but no action regarding unmounting the component has been taken, and there may still be a way to interrupt the process).
  • 1
    Changing/Changed. It's whatever as long as it's consistent though.
  • 0
    To put it another way, a cancellable onChange is fired before internal state is changed.
Add Comment