Skip to content

Consider alternative ReactClass API #124

Closed
@natefaubion

Description

@natefaubion

We are using an alternative ReactClass API internally, and I think it should be considered for upstream.
https://gist.github.com/natefaubion/c639440f2fafd079c5d4eb36012d8e0e

It's basically the module pattern, but has several notable improvements:

  • It doesn't use create-react-class which is unsupported and has lots of unnecessary machinery
  • It's more flexible (we can allocate mutable cells, which gives us instance state, and obviates the need for custom ref handling and effects)
  • It's more efficient (we don't have to rebind event handlers on every render)
  • It forces you to use safe props (only records, no overwritten "key" or "children" props)
  • It uses Union for calculating the available lifecycle fields, so there's no need for special-casing componentDidCatch (only provide the ones you need).
  • It exposes PureComponent, and disallows shouldComponentUpdate in that case.
  • It's more amenable to abstraction since you get the ReactThis reference up front in the constructor, and you don't need to pass it around everywhere.

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