useSharedState() API Docs
Kitchen-sink Example
Here's an example of using the hook with all the options and returns displayed.
import {useSharedState} from '@airstate/react';
export function App() {
const [
state, // the data everyone sees
setState, // change the data everyone sees
isReady, // if the first-sync has occurred or not
error // `any` but typically an instance of `Error`
] = useSharedState<TTypeOfState>(
{ potato: 'brownish' }, // the initial state
{
channel: 'a-specific-room-key', // if you don't want airstate to infer from url
token: 'jwt-signed-by-your-server', // to maintain authentication & authorization
client: customClient, // if you don't want to use the default client
validate: (rawState: any): TTypeOfState => {
// return the validated data
// or throw error
return schema.parse(rawState);
}
}
);
return <>{/* ... */}</>;
}
API
WIP.