Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
can we update an atom state whenver another atom changes in RecoilJS

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 ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can create derived state from other atoms using the selector API:

export const filterAtom = selector({
  key: 'filterAtom',
  get: ({get}) => {
    const timeRange = get(timeRangeAtom);
    return {time: [...timeRange]};
  },
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!