usePersistentUserChoices
function usePersistentUserChoices(options?): {
userChoices: PersistentUserChoices;
saveAudioInputEnabled: (isEnabled) => void;
saveVideoInputEnabled: (isEnabled) => void;
saveAudioInputDeviceId: (deviceId) => void;
saveVideoInputDeviceId: (deviceId) => void;
saveUsername: (username) => void;
};Defined in: packages/react/src/hooks/usePersistentUserChoices.ts:66
Access user choices stored in local storage, such as selected media devices, their on/off state, and the user name.
Parameters
| Parameter | Type |
|---|---|
options | UsePersistentUserChoicesOptions |
Returns
{
userChoices: PersistentUserChoices;
saveAudioInputEnabled: (isEnabled) => void;
saveVideoInputEnabled: (isEnabled) => void;
saveAudioInputDeviceId: (deviceId) => void;
saveVideoInputDeviceId: (deviceId) => void;
saveUsername: (username) => void;
}userChoices
userChoices: PersistentUserChoices;saveAudioInputEnabled
saveAudioInputEnabled: (isEnabled) => void;Parameters
| Parameter | Type |
|---|---|
isEnabled | boolean |
Returns
void
saveVideoInputEnabled
saveVideoInputEnabled: (isEnabled) => void;Parameters
| Parameter | Type |
|---|---|
isEnabled | boolean |
Returns
void
saveAudioInputDeviceId
saveAudioInputDeviceId: (deviceId) => void;Parameters
| Parameter | Type |
|---|---|
deviceId | string |
Returns
void
saveVideoInputDeviceId
saveVideoInputDeviceId: (deviceId) => void;Parameters
| Parameter | Type |
|---|---|
deviceId | string |
Returns
void
saveUsername
saveUsername: (username) => void;Parameters
| Parameter | Type |
|---|---|
username | string |
Returns
void
Example
// Basic — persist a selected microphone.
const { userChoices, saveAudioInputDeviceId } = usePersistentUserChoices();
saveAudioInputDeviceId(userChoices.audioDeviceId);
// Advanced — start with defaults without loading storage.
function PreJoinChoices() {
const { userChoices, saveUsername, saveAudioInputEnabled } = usePersistentUserChoices({
defaults: { username: "Guest" },
preventLoad: true,
});
return <input value={userChoices.username} onChange={(event) => saveUsername(event.target.value)} />;
}