Package com.vaadin.flow.component.react
Class ReactAdapterComponent
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.react.ReactAdapterComponent
- All Implemented Interfaces:
AttachNotifier
,DetachNotifier
,HasElement
,HasStyle
,Serializable
- Direct Known Subclasses:
ReactRouterOutlet
An abstract implementation of an adapter for integrating with React
components. To be used together with a React adapter Web Component that
subclasses the
ReactAdapterElement
JS class. The React adapter Web
Component defines the React JSX template to render the React components with
the specified props mapping, defines the named state that is synchronised
with the server-side Java component, and custom DOM events.
The subclasses should specify the following:
- A
Tag
annotation with the name of the React adapter Web Component. - A
JsModule
annotation with the React adapter Web Component implementation. - An optional
NpmPackage
annotation for npm dependencies of the React adapter Web Component.
- Since:
- 24.4
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected <T> DomListenerRegistration
addStateChangeListener
(String stateName, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, SerializableConsumer<T> listener) Adds the specified listener for the state change event in the React adapter.protected <T> DomListenerRegistration
addStateChangeListener
(String stateName, Class<T> typeClass, SerializableConsumer<T> listener) Adds the specified listener for the state change event in the React adapter.protected Element
getContentElement
(String name) Get the Flow container element that is set up in React template for given name attribute.protected <T> T
Reads the state value from the React adapter.protected <T> T
Reads the state value from the React adapter.protected static <T> T
readFromJson
(elemental.json.JsonValue jsonValue, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) Converts JsonValue into Java object of given type.protected static <T> T
readFromJson
(elemental.json.JsonValue jsonValue, Class<T> typeClass) Converts JsonValue into Java object of given type.protected void
Assigns new value for the state in the React adapter.protected static elemental.json.JsonValue
writeAsJson
(Object object) Converts Java object into JsonValue.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
ReactAdapterComponent
public ReactAdapterComponent()
-
-
Method Details
-
addStateChangeListener
protected <T> DomListenerRegistration addStateChangeListener(String stateName, Class<T> typeClass, SerializableConsumer<T> listener) Adds the specified listener for the state change event in the React adapter.- Type Parameters:
T
- type of the state value- Parameters:
stateName
- state nametypeClass
- type class of the state valuelistener
- the listener callback for receiving value changes- Returns:
- listener registration object
-
addStateChangeListener
protected <T> DomListenerRegistration addStateChangeListener(String stateName, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, SerializableConsumer<T> listener) Adds the specified listener for the state change event in the React adapter.- Type Parameters:
T
- type of the state value- Parameters:
stateName
- state nametypeReference
- type reference of the state valuelistener
- the listener callback for receiving value changes- Returns:
- listener registration object
-
setState
Assigns new value for the state in the React adapter.- Parameters:
stateName
- state namevalue
- value to assign
-
getState
Reads the state value from the React adapter.- Type Parameters:
T
- type of the state value- Parameters:
stateName
- state nametypeClass
- type class of the state value- Returns:
- the current value
-
getState
protected <T> T getState(String stateName, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) Reads the state value from the React adapter.- Type Parameters:
T
- type of the state value- Parameters:
stateName
- state nametypeReference
- type reference of the state value- Returns:
- the current value
-
readFromJson
Converts JsonValue into Java object of given type.- Type Parameters:
T
- type of result instance- Parameters:
jsonValue
- JSON value to convert, notnull
typeClass
- type class of converted object instance- Returns:
- converted object instance
-
readFromJson
protected static <T> T readFromJson(elemental.json.JsonValue jsonValue, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) Converts JsonValue into Java object of given type.- Type Parameters:
T
- type of result instance- Parameters:
jsonValue
- JSON value to convert, notnull
typeReference
- type reference of converted object instance- Returns:
- converted object instance
-
writeAsJson
Converts Java object into JsonValue.- Parameters:
object
- Java object to convert- Returns:
- converted JSON value
-
getContentElement
Get the Flow container element that is set up in React template for given name attribute.- Parameters:
name
- the name attribute for the container element- Returns:
- Element for the Flow container under ReactAdapter element
-