English

Remix is a full stack web framework focused on web fundamentals and modern UX.

Setup

npx create-remix@latest
cd my-remix-app
npm run dev

Route Structure

// app/routes/_index.tsx
export default function Index() {
  return (
    <div>
      <h1>Welcome to Remix</h1>
    </div>
  );
}

Data Loading

// app/routes/posts.tsx
import { json } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';

export async function loader() {
  const posts = await getPosts();
  return json({ posts });
}

export default function Posts() {
  const { posts } = useLoaderData<typeof loader>();
  return (
    <ul>
      {posts.map((post) => (
        <li key={post.id}>{post.title}</li>
      ))}
    </ul>
  );
}

Form Actions

// app/routes/contact.tsx
import { redirect } from '@remix-run/node';

export async function action({ request }) {
  const formData = await request.formData();
  const email = formData.get('email');
  await saveContact(email);
  return redirect('/thank-you');
}

export default function Contact() {
  return (
    <form method="post">
      <input type="email" name="email" required />
      <button type="submit">Subscribe</button>
    </form>
  );
}

Error Handling

export function ErrorBoundary() {
  return (
    <div>
      <h1>Something went wrong</h1>
      <p>Please try again later.</p>
    </div>
  );
}

Why Remix?

  1. Web standards - Uses native forms and HTTP
  2. Nested routing - Parallel data loading
  3. Progressive enhancement - Works without JavaScript
  4. Error boundaries - Graceful error handling
  5. Built-in optimizations - Prefetching and caching
Posted onreactwith tags:
0
0
0
0