-
-
Notifications
You must be signed in to change notification settings - Fork 350
Open
Description
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
Labels
No labels