recoil-nexus icon indicating copy to clipboard operation
recoil-nexus copied to clipboard

Any ideas on how to observe atom changes?

Open nicolas6422 opened this issue 2 years ago • 1 comments

Say I want to setup an observer outside of the react render tree like

import { observe } from 'recoil-nexus';

class Class {
  constructor() {
    observe(someAtom, (oldValue, newValue) => {
      // do something
    })
  }
}

Would this be possible? Figured you'd be the best person to ask 😄

nicolas6422 avatar Oct 15 '22 02:10 nicolas6422

Hi, I think I can help but this doesn't look strictly related to this package, could you please post your question on Stack Overflow and link it here? That would help future Googlers as much as yourself, so other engineers could see the question and provide alternative solutions as well.

luisanton-io avatar Oct 15 '22 12:10 luisanton-io

@luisanton-io is there a reason this isn't part of the package? It seems like a reasonable utility that covers common use cases.

I'm going to try implementing it myself as part of a forked package, but it would be good to see the way you were thinking it should work.

CyberCyclone avatar Jul 06 '23 03:07 CyberCyclone

I haven't been able to figure out a solution yet mostly because I can't find a function that takes a callback and also subscribes. As in, useRecoilCallback is a once off, it's not a subscription.

I've posted a question on SO: https://stackoverflow.com/questions/76634495/react-recoil-outside-of-react-component-observable-subscriptions

CyberCyclone avatar Jul 07 '23 06:07 CyberCyclone

HI @CyberCyclone, I replied to your question.

luisanton-io avatar Jul 08 '23 14:07 luisanton-io