Documents / @faasjs/react / createWindowStates
Function: createWindowStates()
createWindowStates<
T>(defaultStates):WindowStates<T>
Create window-backed shared states with generated hooks, setters, and latest-value refs.
Each key receives an independent internally generated window event name. Components using a generated hook re-render when the matching setter runs, and code outside React can read the latest value from the generated ref.
Type Parameters
T
T extends Record<string, unknown>
Shared state object shape.
Parameters
defaultStates
T
Initial values used to create shared state entries.
Returns
WindowStates<T>
Generated useXxx, setXxx, and xxxRef helpers for each key.
Example
import { createWindowStates } from '@faasjs/react'
export const { useText, setText, textRef } = createWindowStates({
text: '',
})
function Preview() {
const text = useText()
return <span>{text}</span>
}
setText('updated')
console.log(textRef.current)