Can I use openConnectModal outside the ConnectButton component? #386
-
Is there a way to open connect modal automatically (without any click) whenever there is no account connected? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I was able to do this but haven't yet tested fully. I did something like this export const RainbowButton = () => (
<ConnectButton.Custom>
{({ account, chain, openAccountModal, openChainModal, openConnectModal, mounted }) => {
.....
{(() => {
if (!mounted || !account || !chain) {
return (
// notice I added id="connect-button" <-------------------------------------------------
<button onClick={openConnectModal} type="button" id="connect-button">
Connect Wallet
</button>
)
}
....
</ConnectButton.Custom>
); Then in page React.useEffect(() => {
try {
const btn = document.querySelector('#connect-button') as HTMLButtonElement
btn.click()
} catch (error) {
return
}
}, []) It's a bad solution but it will do for me until they expose more APIs. |
Beta Was this translation helpful? Give feedback.
-
This is out now in RainbowKit v0.4.3. You can check out the docs here: https://www.rainbowkit.com/docs/modal-hooks |
Beta Was this translation helpful? Give feedback.
-
@markdalgleish according to the doc
I'm wondering why in my case this is always undefined .... what state is that? |
Beta Was this translation helpful? Give feedback.
This is out now in RainbowKit v0.4.3.
You can check out the docs here: https://www.rainbowkit.com/docs/modal-hooks