mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +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
|
## 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
|
```tsx
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useOcean, OceanConfig, useConsume } from '@oceanprotocol/react'
|
import { useOcean, OceanConfig, useConsume } from '@oceanprotocol/react'
|
||||||
@ -21,8 +40,12 @@ const oceanConfig: OceanConfig = {
|
|||||||
|
|
||||||
export default function MyComponent() {
|
export default function MyComponent() {
|
||||||
// TODO: setup web3 first
|
// TODO: setup web3 first
|
||||||
|
|
||||||
|
// Initialize, get existing, or reinitalize Ocean
|
||||||
const { ocean, account } = useOcean(web3, oceanConfig)
|
const { ocean, account } = useOcean(web3, oceanConfig)
|
||||||
const { consumeAsset, isLoading, step } = useConsume()
|
|
||||||
|
// consume asset
|
||||||
|
const { consumeAsset, isLoading, step } = useConsume(ocean, account)
|
||||||
|
|
||||||
async function handleClick() {
|
async function handleClick() {
|
||||||
const ddo = 'did:op:0x000000000'
|
const ddo = 'did:op:0x000000000'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user