Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda