Skip to content

Component

Anton edited this page Feb 26, 2020 · 10 revisions

Component is a class that allows to implement advanced rendering operations, such as lifecycle methods.

Component: A base class that is usually subclassed to create stateful Preact components.

Name Type & Description
constructor new (props?: !Object, context?: !Object) => Component
Constructor method.
props !Object (optional): The initial component props.
context !Object (optional): The initial context from parent components' getChildContext.
static defaultProps !Object
Properties that will be assigned upon construction of the component.
static getDerivedStateFromProps (props: !Object, state: !Object) => !Object
The function to compute the state from properties.
props* !Object: Component properties.
state* !Object: Component plain state.
_disable
__xalias
boolean
Turns off stateful re-rendering.
context !Object
The context.
props !Object
The properties.
state !Object
The state.
setState (state: !Object, callback?: function(): void) => ?
state* !Object: The state.
callback function(): void (optional): The callback after completion.
forceUpdate (callback?: function(): void) => ?
callback function(): void (optional): The callback after completion.
render (props?: !Object, state?: !Object, context?: !Object) => VNode
The render() function is required for all components. It can inspect the props and state of the component, and should return a Preact element or null.
props !Object (optional): Component properties.
state !Object (optional): Component state.
context !Object (optional): Component context.
componentWillMount () => ?
Called before the component gets mounted to the DOM.
componentDidMount () => ?
Called after the component gets mounted to the DOM.
componentWillUnmount () => ?
Called prior to removal from the DOM.
getChildContext () => !Object
componentWillReceiveProps (nextProps?: !Object, nextContext?: !Object) => ?
Called before new props get accepted.
nextProps !Object (optional): New properties.
nextContext !Object (optional): New context.
shouldComponentUpdate (nextProps?: !Object, nextState?: !Object, nextContext?: !Object) => boolean
Called before render(). Should return false to skip render.
nextProps !Object (optional): New properties.
nextState !Object (optional): New state.
nextContext !Object (optional): New context.
componentWillUpdate (nextProps?: !Object, nextState?: !Object, nextContext?: !Object) => ?
Called before render().
nextProps !Object (optional): New properties.
nextState !Object (optional): New state.
nextContext !Object (optional): New context.
componentDidUpdate (prevProps?: !Object, prevState?: !Object, prevContext?: !Object) => ?
Called after render().
prevProps !Object (optional): Previous properties.
prevState !Object (optional): Previous state.
prevContext !Object (optional): Previous context.
Clone this wiki locally