Skip to content

Commit

Permalink
fix: update last remix-run version in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
abereghici committed Jan 12, 2025
1 parent 280f2ba commit 1b76edc
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Check out the
[Example](https://github.com/abereghici/remix-themes/tree/main/test-apps/react-router-app)
to see it in action.

If you are using Remix.run you can use v1.5.1 of this library or lower, v2 onwards is only react-router v7 compatible.
If you are using Remix.run you can use v1.6.1 of this library or lower, v2 onwards is only react-router v7 compatible.

## Install

Expand Down Expand Up @@ -59,38 +59,42 @@ these parameters on localhost.
```ts
// root.tsx

import {ThemeProvider, useTheme, PreventFlashOnWrongTheme} from 'remix-themes'
import {themeSessionResolver} from './sessions.server'
import {
ThemeProvider,
useTheme,
PreventFlashOnWrongTheme,
} from "remix-themes";
import { themeSessionResolver } from "./sessions.server";

// Return the theme from the session storage using the loader
export const loader: LoaderFunction = async ({request}) => {
const {getTheme} = await themeSessionResolver(request)
export const loader: LoaderFunction = async ({ request }) => {
const { getTheme } = await themeSessionResolver(request);
return {
theme: getTheme(),
}
}
};
};

// Wrap your app with ThemeProvider.
// `specifiedTheme` is the stored theme in the session storage.
// `themeAction` is the action name that's used to change the theme in the session storage.
export default function AppWithProviders() {
const data = useLoaderData()
const data = useLoaderData();
return (
<ThemeProvider specifiedTheme={data.theme} themeAction="/action/set-theme">
<App />
</ThemeProvider>
)
);
}

// Use the theme in your app.
// If the theme is missing in session storage, PreventFlashOnWrongTheme will get
// the browser theme before hydration and will prevent a flash in browser.
// The client code runs conditionally, it won't be rendered if we have a theme in session storage.
function App() {
const data = useLoaderData()
const [theme] = useTheme()
const data = useLoaderData();
const [theme] = useTheme();
return (
<html lang="en" data-theme={theme ?? ''}>
<html lang="en" data-theme={theme ?? ""}>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
Expand All @@ -104,7 +108,7 @@ function App() {
<Scripts />
</body>
</html>
)
);
}
```

Expand Down

0 comments on commit 1b76edc

Please sign in to comment.