Skip to content

The prev value passed to the unwrap fallback is still undefined after the async atom resolves. #2756

Closed Answered by dai-shi
3846masa asked this question in Bug report
Discussion options

You must be logged in to vote
const internalFeatureFlagClientAtom = atom(async (get) => {
  // When user changes, we need to reinitialize the client.
  const user = await get(userAtom);
  const client = new FeatureFlagClient(user);
  await client.initialize();
  return client;
});

const unwrappedFeatureFlagClientAtom = unwrap(internalFeatureFlagClientAtom, (prev) => {
  return prev;
});

const featureFlagClientAtom = atom((get) => {
  get(unwrappedFeatureFlagClientAtom);
  return get(internalFeatureFlagClientAtom);
});

// ...

Replies: 1 comment 12 replies

Comment options

You must be logged in to vote
12 replies
@dai-shi
Comment options

@3846masa
Comment options

@dai-shi
Comment options

@dai-shi
Comment options

Answer selected by 3846masa
@dai-shi
Comment options

@dai-shi
Comment options

@3846masa
Comment options

@dai-shi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants