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

public abstract class ReactAdapterComponent extends Component
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 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 name
      typeClass - type class of the state value
      listener - 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 name
      typeReference - type reference of the state value
      listener - the listener callback for receiving value changes
      Returns:
      listener registration object
    • setState

      protected void setState(String stateName, Object value)
      Assigns new value for the state in the React adapter.
      Parameters:
      stateName - state name
      value - value to assign
    • getState

      protected <T> T getState(String stateName, Class<T> typeClass)
      Reads the state value from the React adapter.
      Type Parameters:
      T - type of the state value
      Parameters:
      stateName - state name
      typeClass - 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 name
      typeReference - type reference of the state value
      Returns:
      the current value
    • readFromJson

      protected static <T> T readFromJson(elemental.json.JsonValue jsonValue, Class<T> typeClass)
      Converts JsonValue into Java object of given type.
      Type Parameters:
      T - type of result instance
      Parameters:
      jsonValue - JSON value to convert, not null
      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, not null
      typeReference - type reference of converted object instance
      Returns:
      converted object instance
    • writeAsJson

      protected static elemental.json.JsonValue writeAsJson(Object object)
      Converts Java object into JsonValue.
      Parameters:
      object - Java object to convert
      Returns:
      converted JSON value
    • getContentElement

      protected Element getContentElement(String name)
      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