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
Tagannotation with the name of the React adapter Web Component. - A
JsModuleannotation with the React adapter Web Component implementation. - An optional
NpmPackageannotation for npm dependencies of the React adapter Web Component.
- Since:
- 24.4
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> DomListenerRegistrationaddStateChangeListener(String stateName, Class<T> typeClass, SerializableConsumer<T> listener) Adds the specified listener for the state change event in the React adapter.protected <T> DomListenerRegistrationaddStateChangeListener(String stateName, tools.jackson.core.type.TypeReference<T> typeReference, SerializableConsumer<T> listener) Adds the specified listener for the state change event in the React adapter.protected ElementgetContentElement(String name) Get the Flow container element that is set up in React template for given name attribute.protected <T> TReads the state value from the React adapter.protected <T> TReads the state value from the React adapter.protected static <T> TreadFromJson(tools.jackson.databind.JsonNode jsonValue, Class<T> typeClass) Converts JsonValue into Java object of given type.protected static <T> TreadFromJson(tools.jackson.databind.JsonNode jsonValue, tools.jackson.core.type.TypeReference<T> typeReference) Converts JsonValue into Java object of given type.protected voidAssigns new value for the state in the React adapter.protected static tools.jackson.databind.node.BaseJsonNodewriteToJson(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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods 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, tools.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
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, notnulltypeClass- type class of converted object instance- Returns:
- converted object instance
-
readFromJson
protected static <T> T readFromJson(tools.jackson.databind.JsonNode jsonValue, tools.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, notnulltypeReference- type reference of converted object instance- Returns:
- converted object instance
-
writeToJson
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
-