Skip to content

Commit

Permalink
Add SSR support to the Remix example
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Jan 17, 2025
1 parent 73676da commit c20f8e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions examples/remix/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./style.css"
import "./App.css"
import { ElectricScripts } from "@electric-sql/react"
import {
Links,
Meta,
Expand All @@ -21,6 +22,7 @@ export function Layout({ children }: { children: React.ReactNode }) {
{children}
<ScrollRestoration />
<Scripts />
<ElectricScripts />
</body>
</html>
)
Expand Down
19 changes: 12 additions & 7 deletions examples/remix/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useShape, preloadShape, getShapeStream } from "@electric-sql/react"
import { useFetchers, Form } from "@remix-run/react"
import { v4 as uuidv4 } from "uuid"
import type { ClientActionFunctionArgs } from "@remix-run/react"
import type { LoaderFunction } from "@remix-run/node"
import { v4 as uuidv4 } from "uuid"
import "../Example.css"
import { matchStream } from "../match-stream"

const itemShape = () => {
return {
url: new URL(`/shape-proxy`, window.location.origin).href,
url: import.meta.env.ELECTRIC_URL || `http://localhost:5173/shape-proxy`,
params: {
table: `items`,
},
Expand All @@ -16,6 +17,10 @@ const itemShape = () => {

type Item = { id: string }

export const loader: LoaderFunction = async () => {
return await preloadShape(itemShape())
}

export const clientLoader = async () => {
return await preloadShape(itemShape())
}
Expand Down Expand Up @@ -91,14 +96,14 @@ export default function Example() {
{isClearing
? ``
: [...itemsMap.values()].map((item: Item, index: number) => (
<p key={index} className="item">
<code>{item.id}</code>
</p>
))}
<p key={index} className="item">
<code>{item.id}</code>
</p>
))}
</div>
)
}

export function HydrateFallback() {
return ``
return <div>Loading...</div>
}

0 comments on commit c20f8e7

Please sign in to comment.