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.
@paramstateKey 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
@paramdefaultStateValue 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. A state value showing defaultStateValue keeps that same
object across updates to other keys of the web view state, but still pass a stable default
(module-level or memoized) if the value is used in an effect's dependency list. Likewise, a saved
value that is deeply equal to the current state value keeps the current object, so saving an
equal new object does not give the state value a new identity.
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
stateKeyKey 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
defaultStateValueValue 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. RunningresetWebViewState()will always update the state value returned to the latestdefaultStateValue, and changing thestateKeywill use the latestdefaultStateValue. However, ifdefaultStateValueis changed while a state isdefaultStateValue(meaning it is reset and has no value), the returned state value will not be updated to the newdefaultStateValue. A state value showingdefaultStateValuekeeps that same object across updates to other keys of the web view state, but still pass a stable default (module-level or memoized) if the value is used in an effect's dependency list. Likewise, a saved value that is deeply equal to the current state value keeps the current object, so saving an equal new object does not give the state value a new identity.@returns
[stateValue, setStateValue, resetWebViewState]webViewStateValue: The current value for the web view state at the key specified ordefaultStateValueif a state was not foundsetWebViewState: Function to use to update the web view state value at the key specifiedresetWebViewState: Function that removes the web view state and resets the value todefaultStateValue@example