🌐 Web Development

Remix

Remix Framework

A React framework based on web standards. Focuses on server rendering and data loading.

πŸ“– Detailed Explanation

Remix is a full-stack React framework developed by the React Router team (Ryan Florence, Michael Jackson), and it was acquired by Shopify in 2022. Guided by the philosophy of "going back to the basics of the web," it makes the most of the browser's default behaviors (HTML form, HTTP caching, progressive enhancement). It aims for Progressive Enhancement, in which core functionality works even without JavaScript.

The core of Remix is loader and action. A loader fetches data on the server for GET requests, and an action handles POST/PUT/DELETE requests. This is similar to the traditional MVC pattern, but it is tightly integrated with React components. Server data is accessed through the useLoaderData and useActionData hooks, and server/client code is written in the same file without a separate API endpoint.

Remix's form handling makes use of the default behavior of the HTML <form>. The Form component works even before JavaScript has loaded, and after JS loads it is enhanced with fetch. useFetcher can handle multiple mutations simultaneously, and optimistic updates (Optimistic UI) are also easy to implement. When an error occurs, the form state is preserved, which provides a good user experience.

In Remix v2 (2023), it was integrated with React Router v6.4, which further strengthened its routing patterns. Nested Routes make nesting layouts natural, and each route loads its data independently, which prevents the Waterfall problem. It supports various server runtimes such as Cloudflare Workers, Deno, and Node.js, and the development experience has been improved with Vite as its foundation.

πŸ’» Code Example

Remix Route (loader + action)
// app/routes/posts._index.tsx
import type { LoaderFunctionArgs, ActionFunctionArgs } from '@remix-run/node';
import { json, redirect } from '@remix-run/node';
import { useLoaderData, useActionData, Form, useNavigation } from '@remix-run/react';
import { prisma } from '~/lib/prisma.server';

// loader - GET μš”μ²­ 처리 (데이터 λ‘œλ“œ)
export async function loader({ request }: LoaderFunctionArgs) {
    const url = new URL(request.url);
    const search = url.searchParams.get('q') || '';

    const posts = await prisma.post.findMany({
        where: search ? {
            OR: [
                { title: { contains: search } },
                { content: { contains: search } },
            ]
        } : undefined,
        include: { author: { select: { name: true } } },
        orderBy: { createdAt: 'desc' },
    });

    return json({ posts, search });
}

// action - POST/PUT/DELETE 처리 (mutation)
export async function action({ request }: ActionFunctionArgs) {
    const formData = await request.formData();
    const intent = formData.get('intent');

    if (intent === 'delete') {
        const id = formData.get('id') as string;
        await prisma.post.delete({ where: { id } });
        return json({ success: true });
    }

    if (intent === 'create') {
        const title = formData.get('title') as string;
        const content = formData.get('content') as string;

        // μœ νš¨μ„± 검사
        const errors: Record<string, string> = {};
        if (!title) errors.title = '제λͺ©μ„ μž…λ ₯ν•˜μ„Έμš”';
        if (!content) errors.content = 'λ‚΄μš©μ„ μž…λ ₯ν•˜μ„Έμš”';

        if (Object.keys(errors).length) {
            return json({ errors }, { status: 400 });
        }

        await prisma.post.create({
            data: { title, content, authorId: 1 }
        });

        return redirect('/posts');
    }

    return json({ error: 'Invalid intent' }, { status: 400 });
}

// μ»΄ν¬λ„ŒνŠΈ
export default function PostsIndex() {
    const { posts, search } = useLoaderData<typeof loader>();
    const actionData = useActionData<typeof action>();
    const navigation = useNavigation();

    const isCreating = navigation.formData?.get('intent') === 'create';

    return (
        <div className="max-w-4xl mx-auto py-8">
            {/* 검색 폼 - GET μš”μ²­ */}
            <Form method="get" className="mb-6">
                <input
                    type="search"
                    name="q"
                    defaultValue={search}
                    placeholder="검색어 μž…λ ₯..."
                    className="border p-2 rounded w-full"
                />
            </Form>

            {/* μƒˆ κΈ€ μž‘μ„± 폼 - POST μš”μ²­ */}
            <Form method="post" className="mb-8 p-4 border rounded">
                <input type="hidden" name="intent" value="create" />

                <input
                    name="title"
                    placeholder="제λͺ©"
                    className="w-full border p-2 rounded mb-2"
                />
                {actionData?.errors?.title && (
                    <p className="text-red-500 text-sm">{actionData.errors.title}</p>
                )}

                <textarea
                    name="content"
                    placeholder="λ‚΄μš©"
                    rows={4}
                    className="w-full border p-2 rounded mb-2"
                />
                {actionData?.errors?.content && (
                    <p className="text-red-500 text-sm">{actionData.errors.content}</p>
                )}

                <button
                    type="submit"
                    disabled={isCreating}
                    className="bg-blue-500 text-white px-4 py-2 rounded disabled:opacity-50"
                >
                    {isCreating ? 'μ €μž₯ 쀑...' : 'κ²Œμ‹œκΈ€ μž‘μ„±'}
                </button>
            </Form>

            {/* κ²Œμ‹œκΈ€ λͺ©λ‘ */}
            <ul className="space-y-4">
                {posts.map(post => (
                    <li key={post.id} className="p-4 border rounded flex justify-between">
                        <div>
                            <h3 className="font-bold">{post.title}</h3>
                            <p className="text-gray-600">{post.author.name}</p>
                        </div>
                        <Form method="post">
                            <input type="hidden" name="intent" value="delete" />
                            <input type="hidden" name="id" value={post.id} />
                            <button type="submit" className="text-red-500">
                                μ‚­μ œ
                            </button>
                        </Form>
                    </li>
                ))}
            </ul>
        </div>
    );
}
useFetcher (Optimistic UI)
// app/routes/posts.$id.tsx
import { useFetcher } from '@remix-run/react';

// μ’‹μ•„μš” λ²„νŠΌ - Optimistic UI
function LikeButton({ postId, likes, isLiked }: {
    postId: string;
    likes: number;
    isLiked: boolean;
}) {
    const fetcher = useFetcher();

    // 낙관적 μ—…λ°μ΄νŠΈ: μš”μ²­ 쀑이면 μ˜ˆμƒ κ²°κ³Ό ν‘œμ‹œ
    const optimisticLikes = fetcher.formData
        ? (isLiked ? likes - 1 : likes + 1)
        : likes;
    const optimisticIsLiked = fetcher.formData
        ? !isLiked
        : isLiked;

    return (
        <fetcher.Form method="post" action={`/posts/${postId}/like`}>
            <button
                type="submit"
                className={`flex items-center gap-1 ${
                    optimisticIsLiked ? 'text-red-500' : 'text-gray-500'
                }`}
                disabled={fetcher.state !== 'idle'}
            >
                {optimisticIsLiked ? '❀️' : '🀍'}
                <span>{optimisticLikes}</span>
            </button>
        </fetcher.Form>
    );
}

// μ—¬λŸ¬ fetcher λ™μ‹œ μ‚¬μš© μ˜ˆμ‹œ
function CommentSection({ postId }: { postId: string }) {
    const fetcher = useFetcher();
    const isSubmitting = fetcher.state === 'submitting';

    return (
        <div>
            <fetcher.Form method="post" action={`/posts/${postId}/comments`}>
                <textarea
                    name="content"
                    placeholder="λŒ“κΈ€μ„ μž…λ ₯ν•˜μ„Έμš”..."
                    className="w-full border p-2 rounded"
                    disabled={isSubmitting}
                />
                <button
                    type="submit"
                    disabled={isSubmitting}
                    className="mt-2 bg-blue-500 text-white px-4 py-2 rounded"
                >
                    {isSubmitting ? '등둝 쀑...' : 'λŒ“κΈ€ 등둝'}
                </button>
            </fetcher.Form>
        </div>
    );
}

πŸ—£οΈ Examples of Practical Conversations

πŸ’Ό Choosing a Framework
"Should I use Next.js or Remix?"

"Next.js has a larger ecosystem and is strong in static generation such as ISR/SSG. Remix is good for apps with a lot of dynamic content, form handling, and interaction. If Progressive Enhancement matters, or you want fine-grained handling of error boundaries and loading states, Remix is the better choice."
πŸ” Code Review
"You're saying to use a loader instead of fetching data in useEffect?"

"Yes, in Remix you fetch data on the server with a loader. There's no client-side Waterfall, SEO is good, and loading states are handled automatically. Fetching in useEffect is an SPA pattern, and Remix takes an approach closer to an MPA."
πŸ“± Technical interview
"What is Remix's Progressive Enhancement?"

"Core functionality works through an HTML form even before JavaScript has loaded, and after JS loads it is enhanced with a better UX (SPA navigation, Optimistic UI). The site works even if the network is slow or JS fails, so accessibility and reliability improve."

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

⚠️ Cautions

  • loader/action are server-only - Using browser APIs (localStorage, window) in a loader/action causes an error. Run client-only code inside useEffect.
  • Form vs form - Remix's <Form> component provides JavaScript enhancement, but a <form> that works without JS is still valid. Use a regular <form> when submitting to an external URL.
  • Integration with React Router - Remix v2 is closely tied to React Router v6.4. You also need to consult the React Router documentation to fully understand Nested Routes, Outlet, and more.

πŸ”— Related Terms

πŸ“š Learn More