react / Component
ComponentLifecycle
<P
, S
, SS
>Type Parameter | Default type |
---|---|
P |
object |
S |
object |
SS |
any |
Parameter | Type |
---|---|
props |
P |
Component
<P
, S
, SS
>
ComponentLifecycle<P, S, SS>.constructor
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1009
Parameter | Type |
---|---|
props |
P |
context |
any |
Component
<P
, S
, SS
>
ComponentLifecycle<P, S, SS>.constructor
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1014
If using the new style context, re-declare this in your class to be the
React.ContextType
of your static contextType
.
Should be used with type annotation or static contextType.
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1007
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1027
[key
: string
]: ReactInstance
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1034
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1028
If set, this.context
will be set at runtime to the current value of the given Context.
https://react.dev/reference/react/Component#static-contexttype
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:989
Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.
Parameter | Type |
---|---|
error |
Error |
errorInfo |
ErrorInfo |
void
ComponentLifecycle.componentDidCatch
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1391
Called immediately after a component is mounted. Setting state here will trigger re-rendering.
void
ComponentLifecycle.componentDidMount
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1370
Called immediately after updating occurs. Not called for the initial render.
The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
Parameter | Type |
---|---|
prevProps |
Readonly <P > |
prevState |
Readonly <S > |
snapshot ? |
SS |
void
ComponentLifecycle.componentDidUpdate
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1433
Called immediately before mounting occurs, and before Component.render. Avoid introducing any side-effects or subscriptions in this method.
Note: the presence of NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate or StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps prevents this from being invoked.
void
16.3, use ComponentLifecycle.componentDidMount componentDidMount or the constructor instead; will stop working in React 17
ComponentLifecycle.componentWillMount
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1449
Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.
Calling Component.setState generally does not trigger this method.
Note: the presence of NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate or StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps prevents this from being invoked.
Parameter | Type |
---|---|
nextProps |
Readonly <P > |
nextContext |
any |
void
16.3, use static StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps instead; will stop working in React 17
ComponentLifecycle.componentWillReceiveProps
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1480
Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as
cancelled network requests, or cleaning up any elements created in componentDidMount
.
void
ComponentLifecycle.componentWillUnmount
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1386
Called immediately before rendering when new props or state is received. Not called for the initial render.
Note: You cannot call Component.setState here.
Note: the presence of NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate or StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps prevents this from being invoked.
Parameter | Type |
---|---|
nextProps |
Readonly <P > |
nextState |
Readonly <S > |
nextContext |
any |
void
16.3, use getSnapshotBeforeUpdate instead; will stop working in React 17
ComponentLifecycle.componentWillUpdate
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1512
Parameter | Type |
---|---|
callback ? |
() => void |
void
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1024
Runs before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it.
Note: the presence of this method prevents any of the deprecated lifecycle events from running.
Parameter | Type |
---|---|
prevProps |
Readonly <P > |
prevState |
Readonly <S > |
null
| SS
ComponentLifecycle.getSnapshotBeforeUpdate
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1427
ReactNode
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1025
Type Parameter |
---|
K extends string | number | symbol |
Parameter | Type |
---|---|
state |
null | S | (prevState : Readonly <S >, props : Readonly <P >) => null | S | Pick <S , K > | Pick <S , K > |
callback ? |
() => void |
void
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1019
Called to determine whether the change in props and state should trigger a re-render.
Component
always returns true.
PureComponent
implements a shallow comparison on props and state and returns true if any
props or states have changed.
If false is returned, Component.render, componentWillUpdate
and componentDidUpdate
will not be called.
Parameter | Type |
---|---|
nextProps |
Readonly <P > |
nextState |
Readonly <S > |
nextContext |
any |
boolean
ComponentLifecycle.shouldComponentUpdate
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1381
Called immediately before mounting occurs, and before Component.render. Avoid introducing any side-effects or subscriptions in this method.
This method will not stop working in React 17.
Note: the presence of NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate or StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps prevents this from being invoked.
void
16.3, use ComponentLifecycle.componentDidMount componentDidMount or the constructor instead
ComponentLifecycle.UNSAFE_componentWillMount
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1464
Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.
Calling Component.setState generally does not trigger this method.
This method will not stop working in React 17.
Note: the presence of NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate or StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps prevents this from being invoked.
Parameter | Type |
---|---|
nextProps |
Readonly <P > |
nextContext |
any |
void
16.3, use static StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps instead
ComponentLifecycle.UNSAFE_componentWillReceiveProps
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1498
Called immediately before rendering when new props or state is received. Not called for the initial render.
Note: You cannot call Component.setState here.
This method will not stop working in React 17.
Note: the presence of NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate or StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps prevents this from being invoked.
Parameter | Type |
---|---|
nextProps |
Readonly <P > |
nextState |
Readonly <S > |
nextContext |
any |
void
16.3, use getSnapshotBeforeUpdate instead
ComponentLifecycle.UNSAFE_componentWillUpdate
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1528