@remix.w/mui
TypeScript icon, indicating that this package has built-in type declarations

0.0.3Β β€’Β PublicΒ β€’Β Published

π™π™šπ™’π™žπ™­ π™’π™žπ™©π™ | ℛℯ𝒢𝒸𝓉 ℳ𝒰𝐼

Purpose

Helps to integrate MUI/Emotion into your Remix Run project.

Installation

npm

npm install "@remix.w/mui@latest"

pnpm

pnpm add "@remix.w/mui@latest"

yarn

yarn isntall "@remix.w/mui@latest"

Conventions

Use the template below or modify your code to include the relevant bits.

entry.client.tsx

import { hydrateRoot as hydrate } from 'react-dom/client';
import { RemixBrowser } from '@remix-run/react';
import { StrictMode } from 'react';

// ----
import { MUIEmotionProvider } from '@remix.w/mui/out/cache/provider.client';

// ---- JSX APP
function App() {
    return (
        <StrictMode>
            <MUIEmotionProvider>
                <RemixBrowser />
            </MUIEmotionProvider>
        </StrictMode>
    );
}

// ---- CLIENT HYDRATION
hydrate(document, <App />);

entry.server.tsx

import { renderToString as render } from 'react-dom/server';
import { EntryContext } from '@remix-run/cloudflare';
import CssBaseline from '@mui/material/CssBaseline';
import { RemixServer } from '@remix-run/react';

// ----
import { withMUI } from "@remix.w/mui/out/cache/provider.server";

export default async function handle(request: Request, status: number, headers: Headers, context: EntryContext) {
    const { MUIEmotionProvider, withMUIStyles } = withMUI();

    // ---- JSX APP
    function App() {
        return (
            <MUIEmotionProvider>
                <CssBaseline />
                <RemixServer context={context} url={request.url} />
            </MUIEmotionProvider>
        );
    }

    // ---- HTML RENDER
    const html = withMUIStyles(render(<App />));

    // ---- RESPONSE HEADERS
    headers.set('Content-Type', 'text/html');

    // ----
    return new Response(`<!DOCTYPE html>${html}`, { status, headers });
}

root.tsx

import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react';
import { MetaFunctionArgs } from "@remix.w/types";
import { CssBaseline } from '@mui/material';

// ----
import { MUIStylesProvider } from "@remix.w/mui";

// ----
export function meta({ data }: MetaFunctionArgs<RootLoaderData>) {
    return ({
        charSet: "utf-8",
        viewport: "width=device-width,initial-scale=1"
    });
}

// ----
export default function Root() {
    return (
        <MUIStylesProvider>
            <html lang="en">
                <head>
                    <Meta />
                    <Links />

                    {/** ---- IMPORTANT ----**/}
                    <meta name="emotion-insertion-point" content="emotion-insertion-point" />
                </head>
                <body>
                    <CssBaseline />
                    <Outlet />
                    <ScrollRestoration />
                    <Scripts />
                    <LiveReload />
                </body>
            </html>
        </MUIStylesProvider>
    );
}

// ---- Don't forget to include the styles provider in your Catch and Error boundaries

export function CatchBoundary() {
    return (
        <MUIStylesProvider>
            <html lang="en">
                <head>
                    {/** ---- IMPORTANT ----**/}
                    <meta name="emotion-insertion-point" content="emotion-insertion-point" />
                </head>
                <body>
                    <...>
                </body>
            </html>
        </MUIStylesProvider>
    );
}

Collaboration

You are welcome to contribute ≧◑≦

LICENSE

MIT

Dependencies (3)

Dev Dependencies (6)

Package Sidebar

Install

npm i @remix.w/mui

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

11.9 kB

Total Files

14

Last publish

Collaborators

  • uceumice