-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(React) Allow Hooks to Be Invoked Without Passing an Account #116
Comments
This comment has been minimized.
This comment has been minimized.
This is a good React component design question, and I'd be happy to continue it if you'd be interested in posting it to sola.na/sse. In the meantime, take a look at how we handle a wallet failing to implement certain features or chains in the example React UI solana-web3.js/examples/react-app/src/routes/root.tsx Lines 53 to 59 in 325925c
|
Hi @alex-bubblemaps, Thanks for your question! We want to make sure to keep signal strong in the GitHub issue tracker – to make sure that it remains the best place to track issues that affect the development of the Solana JavaScript SDK itself. Questions like yours deserve a purpose-built Q&A forum. Unless there exists evidence that this is a bug with the Solana JavaScript SDK itself, please post your question to the Solana Stack Exchange using this link: https://solana.stackexchange.com/questions/ask This automated message is a result of having added the ‘question’ tag. |
Thanks a lot, @steveluscher, for your time and response! I'll post my question on Solana Stack Exchange. About handling an Additionally, my goal is to provide common Web3 properties and methods (like address and signMessage) through a higher-level context. That means I’ll need to call the hook handling signatures in the same place where I retrieve the current address—which could be undefined. To be honest, I haven’t explored this in depth yet. My question was more about the argument passed to the hook, which could be an issue since we can’t conditionally call a hook. 🙂 |
Motivation
Allowing developers to invoke hooks (e.g., useWalletAccountMessageSigner) without requiring an account provides greater flexibility in where these hooks are called. This removes the need to check for an account before rendering a component that depends on the hook. Additionally, it enables the use of these hooks in higher-level components and contexts.
Example Use Case
In a cross-chain application, it can be useful to define an abstract interface with common methods and properties (e.g., address, isConnected, signMessage). To achieve this, we could wrap the application in a BlockchainContext to determine which implementation of the abstract interface to invoke.
For example, if Solana is the active blockchain, we could have a something like this:
Abstract interface:
Solana context implementation:
Solana context provider (using v1):
However, in version 2 (v2), this approach is no longer possible. For example, we can’t provide a method to handle signatures since the new React v2 hook requires an account as an argument.
Details
I’m not sure how these hooks work internally, but a potential solution could be to return undefined when no account is provided.
The text was updated successfully, but these errors were encountered: