Skip to content

Document that events are pooled #3657

Closed
@andersekdahl

Description

@andersekdahl

I ran into an issue where I had an event handler that called setState by passing in a function and accessing e.target.value inside that function. It seems that Reacts synthetic events are "garbage collected" after the event handler has finished executing, which gave me an error when I tried to access value of undefined (since all properties were removed from the event object).

This is fine, and easy to fix by destructuring the event as in the argument (({target: {value}}) => this.setState(...) instead of e => this.setState(...)), but it should probably be documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions