Skip to content

Commit

Permalink
chore(examples): fix ESLint warnings in theme-ui example (remix-run…
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey authored Jul 6, 2022
1 parent 4e46bc4 commit a9013ec
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 37 deletions.
19 changes: 8 additions & 11 deletions examples/theme-ui/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import React, { useState } from "react";
import { hydrate } from "react-dom";
import { CacheProvider } from "@emotion/react";
import { RemixBrowser } from "@remix-run/react";
import type { FunctionComponent } from "react";
import { useState } from "react";
import { hydrate } from "react-dom";

import { ClientStyleContext } from "./styles/context";
import createEmotionCache from "./styles/createEmotionCache";

interface ClientCacheProviderProps {
children: React.ReactNode;
}
import { createEmotionCache } from "./styles/createEmotionCache";

function ClientCacheProvider({ children }: ClientCacheProviderProps) {
const ClientCacheProvider: FunctionComponent = ({ children }) => {
const [cache, setCache] = useState(createEmotionCache());

function reset() {
const reset = () => {
setCache(createEmotionCache());
}
};

return (
<ClientStyleContext.Provider value={{ reset }}>
<CacheProvider value={cache}>{children}</CacheProvider>
</ClientStyleContext.Provider>
);
}
};

hydrate(
<ClientCacheProvider>
Expand Down
6 changes: 3 additions & 3 deletions examples/theme-ui/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { renderToString } from "react-dom/server";
import { CacheProvider } from "@emotion/react";
import createEmotionServer from "@emotion/server/create-instance";
import type { EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import type { EntryContext } from "@remix-run/node"; // Depends on the runtime you choose
import { renderToString } from "react-dom/server";

import { ServerStyleContext } from "./styles/context";
import createEmotionCache from "./styles/createEmotionCache";
import { createEmotionCache } from "./styles/createEmotionCache";

export default function handleRequest(
request: Request,
Expand Down
17 changes: 9 additions & 8 deletions examples/theme-ui/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useContext, useEffect } from "react";
import { withEmotionCache } from "@emotion/react";
import { ThemeProvider } from "@theme-ui/core";
import type { MetaFunction } from "@remix-run/node";
import {
Links,
LiveReload,
Expand All @@ -9,7 +8,9 @@ import {
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import type { MetaFunction, LinksFunction } from "@remix-run/node"; // Depends on the runtime you choose
import { ThemeProvider } from "@theme-ui/core";
import type { ReactNode } from "react";
import { useContext, useEffect } from "react";

import { ServerStyleContext, ClientStyleContext } from "./styles/context";

Expand All @@ -19,10 +20,9 @@ export const meta: MetaFunction = () => ({
viewport: "width=device-width,initial-scale=1",
});

interface DocumentProps {
children: React.ReactNode;
}

type DocumentProps = {
children: ReactNode;
};
const Document = withEmotionCache(
({ children }: DocumentProps, emotionCache) => {
const serverStyleData = useContext(ServerStyleContext);
Expand All @@ -40,7 +40,7 @@ const Document = withEmotionCache(
});
// reset cache to reapply global styles
clientStyleData?.reset();
}, []);
}, [clientStyleData, emotionCache.sheet]);

return (
<html lang="en">
Expand All @@ -55,6 +55,7 @@ const Document = withEmotionCache(
/>
))}
</head>

<body>
{children}
<ScrollRestoration />
Expand Down
3 changes: 0 additions & 3 deletions examples/theme-ui/app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/** @jsx jsx */
import React from "react";
import { jsx } from "@theme-ui/core";
import { Link } from "@remix-run/react";

export default function Index() {
Expand Down
3 changes: 0 additions & 3 deletions examples/theme-ui/app/routes/jokes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/** @jsx jsx */
import React from "react";
import { jsx } from "@theme-ui/core";
import { Link } from "@remix-run/react";

export default function Jokes() {
Expand Down
12 changes: 6 additions & 6 deletions examples/theme-ui/app/styles/context.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { createContext } from "react";
import { createContext } from "react";

export interface ServerStyleContextData {
export type ServerStyleContextData = {
key: string;
ids: Array<string>;
ids: string[];
css: string;
}
};

export const ServerStyleContext = createContext<
ServerStyleContextData[] | null
>(null);

export interface ClientStyleContextData {
export type ClientStyleContextData = {
reset: () => void;
}
};

export const ClientStyleContext = createContext<ClientStyleContextData | null>(
null
Expand Down
4 changes: 1 addition & 3 deletions examples/theme-ui/app/styles/createEmotionCache.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import createCache from "@emotion/cache";

export default function createEmotionCache() {
return createCache({ key: "css" });
}
export const createEmotionCache = () => createCache({ key: "css" });

0 comments on commit a9013ec

Please sign in to comment.