Recoil icon indicating copy to clipboard operation
Recoil copied to clipboard

Set value to `atomFamily` from `get` method of `selectorFamily`.

Open LvChengbin opened this issue 2 years ago • 0 comments

import { atomFamily, selectorFamily } from 'recoil';

export const tagState = atomFamily( { ... } )

export const tagListState = selectorFamily( {
    key : 'list',
    get( options ) {
        return async () => {
            const list = await getList();
            list.forEach( ( item ) => {
                // I want to set data here.
                set( tagState( item.id ), item );
            } );

            return list;
        };
    }
} );

As the code above, I want to store each tag into an atom after loading them as an array from remote server. What is the best way for doing this?

LvChengbin avatar Sep 28 '22 12:09 LvChengbin