+
Skip to content

Feature: class-based Component API #85

@mindplay-dk

Description

@mindplay-dk

Should we add support for the class-based Component API?

This could also be implemented as a separate package - and, interestingly, would work with React/Preact as well, enabling them to use hooks in render-methods too.

Here's a working prototype:

https://codesandbox.io/s/fre-component-i6sbs

For now, the prototype requires manually calling a useComponent function to wrap a Component subclass to a function using only hooks. (We might consider integrating this in the h function, where you could check if e.g. type.prototype.render is present, which it is on Component subclasses, but isn't on functional components.)

Features supported so far:

  • constructor(props)
  • componentDidMount()
  • componentWillUnmount()
  • props
  • state
  • render()
  • forceUpdate()
  • static defaultProps
  • static displayName
  • setState(state, callback)
  • setState(function, callback)
  • shouldComponentUpdate(nextProps, nextState)
  • componentDidUpdate(prevProps, prevState, snapshot)
  • static getDerivedStateFromProps(props, state)
  • static getDerivedStateFromError(error)
  • componentDidCatch(error, info)
  • getSnapshotBeforeUpdate(prevProps, prevState)

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

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载