Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/routes/docs/tutorials/react/step-4/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Create a new file `src/lib/context/user.jsx` and add the following code to it.
```js
import { createContext, useContext, useEffect, useState } from "react";
import { account } from "../appwrite";
import { ID } from "appwrite";

const UserContext = createContext();

Expand All @@ -36,7 +37,7 @@ export function UserProvider(props) {
}

async function register(email, password) {
await account.create(email, password);
await account.create(ID.unique(), email, password);
await login(email, password);
}

Expand Down
49 changes: 49 additions & 0 deletions src/routes/docs/tutorials/react/step-6/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,52 @@ export function IdeasProvider(props) {
}
```

# Using `IdeasContext`

Update `src/App.jsx` to use the `IdeasProvider`:

```js
import { Login } from "./pages/Login";
import { Home } from "./pages/Home";
import { UserProvider, useUser } from "./lib/context/user";
import { IdeasProvider } from "./lib/context/ideas";

function App() {
const isLoginPage = window.location.pathname === "/login";

return (
<div>
<UserProvider>
<Navbar /> {/* Add the navbar before page content */}
<IdeasProvider>
<main>{isLoginPage ? <Login /> : <Home />}</main>
</IdeasProvider>
</UserProvider>
</div>
);
}

function Navbar() {
const user = useUser();

return (
<nav>
<a href="/">Idea tracker</a>
<div>
{user.current ? (
<>
<span>{user.current.email}</span>
<button type="button" onClick={() => user.logout()}>
Logout
</button>
</>
) : (
<a href="/login">Login</a>
)}
</div>
</nav>
);
}

export default App;
```