im quite new to recoiljs atom and stuff. Assumming i have 2 atoms
timeRangeAtom
which determines the time range of the selection
export const timeRangeAtom = atom<Array<string>>({
key: 'timeRangeAtom',
default: [
dayjs().subtract(7, 'day').format(DateFormat),
dayjs().subtract(1, 'day').format(DateFormat),
],
});
filterAtoms
which determines the current user selection of all filters ( one of them is timeRange
)
export const filterAtom = atom<any>({
key: 'filterAtom',
default: {time: [] },
});
Now in my code, whenever user select a date, i will update the timeRangeAtom
value. I'm doing this by calling setTime
of useRecoilState
const [time, setTime] = useRecoilState(
timeRangeAtom,
);
Now my question is how can i also sync this change to my filterAtom.time
whenever timeRangeAtom
change ?
One way is i manually setFilterAtom by calling useRecoilState, but it seems quite tedious and duplicate code. So im not sure is there any other ways ?