I'm resurrecting #249, as I've run into a more concrete use-case for event.persist() than the one that prompted #249.
Since component updates are not guaranteed to be synchronous in React 16+, the optional callback for setState may be called asynchronously on the JS side of things. This means that doing something like passing a SyntheticEvent to a consumer callback within that callback will result in ReactJS spitting out a big ugly warning about the event having been recycled.
Without persist()
void handleClick(SyntheticMouseEvent event) {
setState({}, () {
// Ruh roh Scoobs... this could be recycled when they access it.
props.someConsumerCallbackThatNeedsTheEvent(event);
});
}
With persist()
void handleClick(SyntheticMouseEvent event) {
event.persist();
setState({}, () {
// All good... event is persisted and accessible for the consumer.
props.someConsumerCallbackThatNeedsTheEvent(event);
});
}
I'm resurrecting #249, as I've run into a more concrete use-case for
event.persist()
than the one that prompted #249.Since component updates are not guaranteed to be synchronous in React 16+, the optional callback for
setState
may be called asynchronously on the JS side of things. This means that doing something like passing aSyntheticEvent
to a consumer callback within that callback will result in ReactJS spitting out a big ugly warning about the event having been recycled.Without persist()
With persist()