jotaijs / jotai-apollo

Apollo graphql client integration for jotai :rocket: :ghost:
MIT License
50 stars 4 forks source link

Jotai Apollo: atomsWithQuery within react tree #11

Open yassuge opened 1 year ago

yassuge commented 1 year ago

Hi Mo,

Currently, I'm working with the RedwoodApolloProvider and I'm finding the use of the useApolloClient hook quite valuable for obtaining the client. However, I've encountered a situation where I'm uncertain about the best approach to handle it.

As far as I understand, Redwood doesn't offer a seamless method to define the client outside of the React tree and then pass it to the provider. This leads me to call atomsWithQuery from within the React tree itself (to avoid calling hook for the client from outside the render function), as it requires the client to function properly. I'm wondering if this pattern is supported or if you have any experience with it. If so, I would greatly appreciate any insights or examples you might have.

I've attempted a few methods, such as making a plain call (which triggered infinite rerendering) and using useMemo (which didn't update with new data), but I haven't found the ideal solution yet.

Thanks in advance for your assistance

Aslemammad commented 1 year ago

@dai-shi There was a pattern that supported creating atoms in the component body, I wonder if there's any documentation to it.

dai-shi commented 1 year ago

Do you mean something like this? https://twitter.com/dai_shi/status/1697396138578759985

Aslemammad commented 1 year ago

Exactly this, Does it help, Yass?

On Sat, 2 Sept 2023, 03:24 Daishi Kato, @.***> wrote:

Do you mean something like this? https://twitter.com/dai_shi/status/1697396138578759985

— Reply to this email directly, view it on GitHub https://github.com/jotaijs/jotai-apollo/issues/11#issuecomment-1703530753, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJBMICBR26Q5IR64XCU77QLXYJYTXANCNFSM6AAAAAA4HTX5KM . You are receiving this because you commented.Message ID: @.***>

yassuge commented 1 year ago

looks like a good way to do, will try it out! thank you both