get all values from atomfamily in recoil

49 Views Asked by At

I want to create an object using all the values from an atomFamily. The current SO answers say how to read values from atomFamily, but I struggle when I try to read values from all the underlying atoms by looping through the keys.

const requestObj:any = {};
keys.map((key:string) => {
  const val = useRecoilValue(myAtomFamily(key)); //Invalid hook call
  requestObj[key] = val;
});
//Call API with requestObj

How to deal with such case? Should I use a selectorFamily?

0

There are 0 best solutions below