-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: cleanup / improve docs site (#1484)
Partially address #1436 --------- Co-authored-by: Sam Willis <[email protected]>
- Loading branch information
1 parent
beea50d
commit 0b171d5
Showing
19 changed files
with
2,089 additions
and
5,160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
outline: deep | ||
--- | ||
|
||
# React integration | ||
|
||
To use Electric with React, we maintain a React provider and hook to simplify reading shape data in components. | ||
|
||
Example usage in a component. | ||
```tsx | ||
import { useShape } from "@electric-sql/react" | ||
|
||
export default function MyComponent() { | ||
const { isUpToDate, data: fooData } = useShape({ | ||
url: `http://localhost:3000/v1/shape/foo`, | ||
}) | ||
|
||
if (!isUpToDate) { | ||
return <div>loading</div> | ||
} | ||
|
||
return ( | ||
<div> | ||
{data.map(foo => <div>{foo.title}</div>)} | ||
</div> | ||
) | ||
} | ||
``` | ||
|
||
You should wrap your application with a `ShapeProvider` which maintains a global cache of Shapes and ShapeStreams. | ||
|
||
Other helpful functions: | ||
|
||
- `useShapeContext` — access the Shape Context | ||
- `preloadShape` — useful to call in route loading functions or elsewhere when you want to ensure Shape data is loaded before rendering a route or component. | ||
- `getShapeStream` — get (or create) a ShapeStream off the global cache | ||
- `getShape` — get (or create) a Shape off the global cache | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,4 @@ Why build APIs and write code to fetch data over the network when you could just | |
<br /> | ||
<br /> | ||
--> | ||
--> |
Oops, something went wrong.