Skip to content
Discussion options

You must be logged in to vote

Inside useMemo, it:
Tries to retrieve an existing key pair.
If none exists, it generates a new one using createEphemeralKeyPair() and commits it to the store.

// Memoize the key pair so it's created only once unless dependencies change
 const ephemeralKeyPair = useMemo(() => {
   // Try to get an existing key pair
   let keyPair = getEphemeralKeyPair();


 // If there's none, create and store a new one
   if (!keyPair) {
     keyPair = createEphemeralKeyPair();
     commitEphemeralKeyPair(keyPair); // Save it for future use
   }

  return keyPair; // Return the key pair (either existing or newly created)
 }, [commitEphemeralKeyPair, getEphemeralKeyPair]);

 return ephemeralKeyPair;
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by DefenceHack
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants