Categories
Mastering Development

Can the default value of a Recoil atom be an object?

Can I set the default value of a Recoil atom to be an object?

e.g.:

export const currentUserState = atom({
  key: 'currentUserState',
  default: { name: '', email: '', userId: null },
});

And then set it with:

import { currentUserState } from '../atoms/atoms';

const setUserState = useSetRecoilState(currentUserState);
setUserState(name: 'John', email: 'foo@bar.com', userId: getRand());

Leave a Reply

Your email address will not be published. Required fields are marked *