score:1

yes, a recoil atom can be an object.

i have written this code, which you can see below in the working demo.

 const changevalue = () => {
    setuserstate({ name: "john", email: "foo@bar.com", userid: math.random() });
  };

working demo

codesandbox

score:3

yes, it is allowed. recoil atom state can be an object. you have initialized the atom correctly, but when you set the atom you have to pass an object since the state is object.

initialize the currentuserstate atom

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

and then set the atom state as follows

import {currentuserstate} from '../recoilstate/atoms';

const setuserstate = usesetrecoilstate(currentuserstate);

setuserstate({
  name: 'john', 
  email: 'foo@bar.com', 
  userid: getrand()
});

Related Query

More Query from same tag