Skip to content

Aren't updater functions in state an antipattern? #1717

Description

@MrSkinny

In documentation here:
https://reactjs.org/docs/context.html#updating-context-from-a-nested-component

An updater function is placed directly in the state object for the sole purpose of passing it down through context:

this.state = {
  theme: themes.light,
  toggleTheme: this.toggleTheme,
};

This seems like an odd antipattern. I've never placed a method in state before. Shouldn't state be exclusively for properties that affect rendering and change over time?

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