public abstract class Component
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Component.SetStateCallback
Callback function for updating state.
|
Constructor and Description |
---|
Component() |
Modifier and Type | Method and Description |
---|---|
protected void |
componentDidCatch(elemental2.core.JsError error,
ReactErrorInfo info)
The componentDidCatch() method works like a JavaScript catch {} block, but for components.
|
protected void |
componentDidMount()
This method is invoked after a component is attached to the DOM.
|
protected void |
componentDidUpdate(jsinterop.base.JsPropertyMap<java.lang.Object> prevProps,
jsinterop.base.JsPropertyMap<java.lang.Object> prevState)
This method is invoked immediately after updating occurs.
|
protected void |
componentWillUnmount()
This method is invoked immediately before a component is unmounted and destroyed.
|
protected java.lang.String |
getKey()
Return the key associated with the component if any.
|
protected void |
performComponentDidCatch(elemental2.core.JsError error,
ReactErrorInfo info)
Wrapper method that delegates to the
componentDidCatch(JsError, ReactErrorInfo) method. |
protected void |
performComponentDidMount()
Wrapper method that delegates to the
componentDidMount() method. |
protected void |
performComponentDidUpdate(jsinterop.base.JsPropertyMap<java.lang.Object> prevProps,
jsinterop.base.JsPropertyMap<java.lang.Object> prevState)
Wrapper method that delegates to the
componentDidUpdate(JsPropertyMap, JsPropertyMap) method. |
protected void |
performComponentWillUnmount()
Wrapper method that delegates to the
componentWillUnmount() method. |
protected void |
performPostConstruct()
Wrapper method that delegates to the
postConstruct() method. |
protected ReactNode |
performRender()
Wrapper method that delegates to the
render() method. |
protected boolean |
performShouldComponentUpdate(jsinterop.base.JsPropertyMap<java.lang.Object> nextProps,
jsinterop.base.JsPropertyMap<java.lang.Object> nextState)
Wrapper method that delegates to the
shouldComponentUpdate(JsPropertyMap, JsPropertyMap) method. |
protected void |
postConstruct()
This method is invoked after the component is constructed and bound to a native react component.
|
protected jsinterop.base.JsPropertyMap<java.lang.Object> |
props()
Return the component props from the native component.
|
protected abstract ReactNode |
render()
Render the component.
|
protected void |
scheduleRender(boolean force)
Schedule this component for re-rendering.
|
protected void |
scheduleStateUpdate(Component.SetStateCallback callback)
Schedule a shallow merge of supplied state into current state.
|
protected void |
scheduleStateUpdate(Component.SetStateCallback callback,
Procedure onStateUpdateComplete)
Schedule a shallow merge of supplied state into current state.
|
protected void |
scheduleStateUpdate(jsinterop.base.JsPropertyMap<java.lang.Object> state)
Schedule a shallow merge of supplied state into current state.
|
protected void |
scheduleStateUpdate(jsinterop.base.JsPropertyMap<java.lang.Object> state,
Procedure onStateUpdateComplete)
Schedule a shallow merge of supplied state into current state.
|
protected void |
setInitialState(jsinterop.base.JsPropertyMap<java.lang.Object> state)
Set the initial state of the component.
|
protected boolean |
shouldComponentUpdate(jsinterop.base.JsPropertyMap<java.lang.Object> nextProps,
jsinterop.base.JsPropertyMap<java.lang.Object> nextState)
Use this method to let React know if a component's output is not affected
by the current change in state or props.
|
protected jsinterop.base.JsPropertyMap<java.lang.Object> |
state()
Return the component state from the native component.
|
protected final void setInitialState(@Nonnull jsinterop.base.JsPropertyMap<java.lang.Object> state)
state
- the state.protected final jsinterop.base.JsPropertyMap<java.lang.Object> state()
protected final jsinterop.base.JsPropertyMap<java.lang.Object> props()
@Nullable protected final java.lang.String getKey()
protected final void scheduleStateUpdate(@Nonnull jsinterop.base.JsPropertyMap<java.lang.Object> state)
state
- the object literal representing state.protected final void scheduleStateUpdate(@Nonnull jsinterop.base.JsPropertyMap<java.lang.Object> state, @Nullable Procedure onStateUpdateComplete)
state
- the object literal representing state.onStateUpdateComplete
- a callback that will be invoked after state has been updated.protected final void scheduleStateUpdate(@Nonnull Component.SetStateCallback callback)
callback
- the callback that will be invoked to update state.protected void scheduleStateUpdate(@Nonnull Component.SetStateCallback callback, @Nullable Procedure onStateUpdateComplete)
callback
- the callback that will be invoked to update state.onStateUpdateComplete
- a callback that will be invoked after state has been updated.protected final void scheduleRender(boolean force)
If the force parameter is true then the shouldComponentUpdate(JsPropertyMap, JsPropertyMap)
will be skipped
and it is equivalent to calling forceUpdate() on the native react component. See the
React Component documentation for more
details.
If the force parameter is true then the shouldComponentUpdate(JsPropertyMap, JsPropertyMap)
will be
invoked. This is equivalent to calling setState({}) on the native react component.
force
- true to skip shouldComponentUpdate during re-render, false otherwise.@Nullable protected abstract ReactNode render()
@Nullable protected ReactNode performRender()
render()
method.
This method exists to give middleware a mechanism to hook into component lifecycle step.protected void performPostConstruct()
postConstruct()
method.
This method exists to give middleware a mechanism to hook into component lifecycle step.protected void postConstruct()
render()
, therefore
setting state in this method will not trigger a re-rendering. This replaces the
componentWillMount
lifecycle method from react as well as the code that appears in constructors in native React ES6
components.protected void componentDidMount()
protected void performComponentDidMount()
componentDidMount()
method.
This method exists to give middleware a mechanism to hook into component lifecycle step.protected void componentDidUpdate(@Nullable jsinterop.base.JsPropertyMap<java.lang.Object> prevProps, @Nullable jsinterop.base.JsPropertyMap<java.lang.Object> prevState)
prevProps
- the props before the component was updated.prevState
- the state before the component was updated.protected void performComponentDidUpdate(@Nullable jsinterop.base.JsPropertyMap<java.lang.Object> prevProps, @Nullable jsinterop.base.JsPropertyMap<java.lang.Object> prevState)
componentDidUpdate(JsPropertyMap, JsPropertyMap)
method.
This method exists to give middleware a mechanism to hook into component lifecycle step.prevProps
- the props before the component was updated.prevState
- the state before the component was updated.protected void componentWillUnmount()
componentDidMount()
See the React Component documentation for more details.protected void performComponentWillUnmount()
componentWillUnmount()
method.
This method exists to give middleware a mechanism to hook into component lifecycle step.protected void componentDidCatch(@Nonnull elemental2.core.JsError error, @Nonnull ReactErrorInfo info)
Note that error boundaries only catch errors in the components below them in the tree. An error boundary can’t catch an error within itself. If an error boundary fails trying to render the error message, the error will propagate to the closest error boundary above it. This, too, is similar to how catch {} block works in JavaScript.
error
- the error that has been thrown.info
- information about component stack during thrown error.protected void performComponentDidCatch(@Nonnull elemental2.core.JsError error, @Nonnull ReactErrorInfo info)
componentDidCatch(JsError, ReactErrorInfo)
method.
This method exists to give middleware a mechanism to hook into component lifecycle step.error
- the error that has been thrown.info
- information about component stack during thrown error.protected boolean shouldComponentUpdate(@Nullable jsinterop.base.JsPropertyMap<java.lang.Object> nextProps, @Nullable jsinterop.base.JsPropertyMap<java.lang.Object> nextState)
This method is invoked before rendering when new props or state are being received.
This method is not called for the initial render or when scheduleRender(boolean)
} is called
with the force parameter set to true.
Returning false does not prevent child components from re-rendering when their state changes.
If this method returns false, then render()
, and componentDidUpdate(JsPropertyMap, JsPropertyMap)
will not be invoked. In the future React may treat this method as a hint rather than a strict directive, and
returning false may still result in a re-rendering of the component.
nextProps
- the new properties of the component.nextState
- the new state of the component.protected boolean performShouldComponentUpdate(@Nullable jsinterop.base.JsPropertyMap<java.lang.Object> nextProps, @Nullable jsinterop.base.JsPropertyMap<java.lang.Object> nextState)
shouldComponentUpdate(JsPropertyMap, JsPropertyMap)
method.
This method exists to give middleware a mechanism to hook into component lifecycle step.nextProps
- the new properties of the component.nextState
- the new state of the component.