A SurrealDB client for React, based on SurrealDB.js
npm install @foretag.dev/react-surrealA SurrealDB client for React, based on SurrealDB.js
Currently supports React 18 and above.
ts
// app/layout.tsx
'use client';import React from 'react';
import Surreal from 'surrealdb.js';
import { SurrealProvider } from '@foretag.dev/react-surreal';
const db = new Surreal(process.env.NEXT_PUBLIC_SURREAL_HOST);
export default function RootLayout({ children, }: {
children: React.ReactNode
}) {
return database={db}
>
{children}
}
`The following hooks are provided:
-
useAuth - Handles authentication to SurrealDB, this exports: signIn, signOut, signUp methods & isAuth`ts
import { useAuth } from '@foretag.dev/react-surreal';const LoginPage = () => {
// ...
const { signIn, signOut, signUp, isAuth } = useAuth();
}
`-
useQuery - Queries to SurrealDB, this exports: data, loading, error, refetch, status & time`ts
import { useQuery } from '@foretag.dev/react-surreal';const AccountPage = () => {
// ...
const { data, loading } = useQuery('SELECT * FROM account');
}
``