Skip to content
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

add context provider docs #1585

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/src/routes/docs/[...3]modules/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,41 @@ function App() {
}
```

## Using the `Web3OnboardProvider`
You can use the context provider `Web3OnboardProvider` to better manage global state. Simply wrap the provider around your `App` and
the initialized web3Onboard instance will be available in all children components. See example below.

```ts
import { Web3OnboardProvider, init } from '@web3-onboard/react'
import injectedModule from '@web3-onboard/injected-wallets'
const INFURA_KEY = ''
const ethereumRopsten = {
id: '0x3',
token: 'rETH',
label: 'Ethereum Ropsten',
rpcUrl: `https://ropsten.infura.io/v3/${INFURA_KEY}`
}
const chains = [ethereumRopsten]
const wallets = [injectedModule()]
const web3Onboard = init({
wallets,
chains,
appMetadata: {
name: "Web3-Onboard Demo",
icon: '<svg>App Icon</svg>',
description: "A demo of Web3-Onboard."
}
})
function MyApp({ Component, pageProps }) {
return (
<Web3OnboardProvider web3Onboard={web3Onboard}>
<Component {...pageProps} />
</Web3OnboardProvider>
)
}
export default MyApp
```

## `init`

The `init` function must be called before any hooks can be used. The `init` function just initializes `web3-onboard` and makes it available for all hooks to use. For reference check out the [initialization docs for `@web3-onboard/core`](./core.md#initialization)
Expand Down