FunctionuseWebViewState

A React hook for working with a state object tied to a webview. Returns a WebView state value and a function to set it. Use similarly to useState.

Only used in WebView iframes.

@param stateKey Key of the state value to use. The webview state holds a unique value per key.

WARNING: MUST BE STABLE - const or wrapped in useState, useMemo, etc. The reference must not be updated every render

@param defaultStateValue Value to use if the web view state didn't contain a value for the given 'stateKey'

Note: this parameter is internally assigned to a ref, so changing it will not cause any hooks to re-run with its new value. Running resetWebViewState() will always update the state value returned to the latest defaultStateValue, and changing the stateKey will use the latest defaultStateValue. However, if defaultStateValue is changed while a state is defaultStateValue (meaning it is reset and has no value), the returned state value will not be updated to the new defaultStateValue.

@returns [stateValue, setStateValue, resetWebViewState]

  • webViewStateValue: The current value for the web view state at the key specified or defaultStateValue if a state was not found
  • setWebViewState: Function to use to update the web view state value at the key specified
  • resetWebViewState: Function that removes the web view state and resets the value to defaultStateValue

@example

const [lastPersonSeen, setLastPersonSeen] = useWebViewState('lastSeen', 'No one');
  • Type Parameters

    • T

    Parameters

    • stateKey: string
    • defaultStateValue: T

    Returns [webViewStateValue: T, setWebViewState: ((stateValue: T) => void), resetWebViewState: (() => void)]