Skip to content
Open
Show file tree
Hide file tree
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
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,56 @@ React wrapper for working with [`@comapeo/core`](https://github.com/digidem/coma
npm install react @tanstack/react-query@5 @comapeo/core-react @comapeo/schema @comapeo/core @comapeo/ipc
```

## Setup

### Basic Setup

Wrap your application with `ClientApiProvider` and a React Query `QueryClientProvider`:

```tsx
import { ClientApiProvider } from '@comapeo/core-react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'

const queryClient = new QueryClient()

function App() {
return (
<QueryClientProvider client={queryClient}>
<ClientApiProvider clientApi={clientApi}>
<MyApp />
</ClientApiProvider>
</QueryClientProvider>
)
}
```

### Map Sharing Setup

To use the map sharing hooks, you also need to wrap your application with `MapServerProvider`. Create a `MapServerState` instance and call `setPort()` once the `@comapeo/map-server` has started:

```tsx
import { createMapServerState, MapServerProvider } from '@comapeo/core-react'

const mapServerState = createMapServerState()

// When your map server starts and you know the port:
mapServerState.setPort(8080)

function App() {
return (
<QueryClientProvider client={queryClient}>
<ClientApiProvider clientApi={clientApi}>
<MapServerProvider mapServerState={mapServerState}>
<MyApp />
</MapServerProvider>
</ClientApiProvider>
</QueryClientProvider>
)
}
```

Hooks that communicate with the map server (e.g. `useSendMapShare`, `useAcceptMapShare`) will queue their requests until `setPort()` is called, so the provider can be mounted before the server is ready.

## API Documentation

Still a work in progress. Currently lives in [`docs/API.md`](./docs/API.md).
Expand Down
663 changes: 610 additions & 53 deletions docs/API.md

Large diffs are not rendered by default.

Loading