The initial state.
Optional
updateEvent: string = 'set'The event name that triggers a state update.
// Define initial state
type State = { count: number };
const initialState: State = { count: 0 };
// Use the hook in a component
const MyComponent: React.FC = () => {
const syncState = useSyncState<State>(initialState, 'increment');
// Use the state in an event handler
const handleClick = () => {
syncState.set('count', syncState.get('count') + 1);
syncState.dispatch('increment');
};
return (
<div>
<p>Count: {syncState.get('count')}</p>
<button onClick={handleClick}>Increment</button>
</div>
);
};
*
ReactiumSyncState to understand the underlying synchronized state object.
A React hook that creates a synchronized state object.