mirror of
https://github.com/oceanprotocol/react.git
synced 2024-12-23 01:29:49 +01:00
add an OceanProvider
This commit is contained in:
parent
c7558bd769
commit
7310bcafc9
25
README.md
25
README.md
@ -10,6 +10,25 @@ npm install @oceanprotocol/react
|
||||
|
||||
## Usage
|
||||
|
||||
First, wrap your App with the `OceanProvider`:
|
||||
|
||||
```tsx
|
||||
import React from 'react'
|
||||
import { OceanProvider } from '@oceanprotocol/react'
|
||||
|
||||
export default function MyApp({ children }: { children: any }) {
|
||||
return (
|
||||
<OceanProvider>
|
||||
<h1>My App</h1>
|
||||
{children}
|
||||
</OceanProvider>
|
||||
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Then within your component use the provided hooks to interact with Ocean's functionality:
|
||||
|
||||
```tsx
|
||||
import React from 'react'
|
||||
import { useOcean, OceanConfig, useConsume } from '@oceanprotocol/react'
|
||||
@ -21,8 +40,12 @@ const oceanConfig: OceanConfig = {
|
||||
|
||||
export default function MyComponent() {
|
||||
// TODO: setup web3 first
|
||||
|
||||
// Initialize, get existing, or reinitalize Ocean
|
||||
const { ocean, account } = useOcean(web3, oceanConfig)
|
||||
const { consumeAsset, isLoading, step } = useConsume()
|
||||
|
||||
// consume asset
|
||||
const { consumeAsset, isLoading, step } = useConsume(ocean, account)
|
||||
|
||||
async function handleClick() {
|
||||
const ddo = 'did:op:0x000000000'
|
||||
|
Loading…
Reference in New Issue
Block a user