New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

elysia-react-router

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia-react-router

Use React Router v7 or Remix with Elysia with HMR support!

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
increased by140%
Maintainers
0
Weekly downloads
 
Created
Source

Elysia React Router and Remix

Use React Router v7 or Remix with Elysia with HMR support! Closes a long-standing elysia plugin request https://github.com/elysiajs/elysia/issues/12

[!IMPORTANT]

Migration to React Router v7 from Remix.

Usage with React Router

In development mode it uses vite under the hood, and in production serves the build directory and performs SSR requests.

import { Elysia } from "elysia";
import { reactRouter } from "elysia-react-router";

new Elysia()
    .use(await reactRouter())
    .get("/some", "Hello, world!")
    .listen(3000, console.log);

Quick start

bun create react-router@latest --template kravetsone/elysia-react-router/example

Options

KeyTypeDefaultDescription
mode?"development" | "production"process.env.NODE_ENV || "development"In development mode it starts vite, and in production it just serves static and performs SSR requests.
basename?string"/"The base path for the application. This should match the basename in your vite config.
buildDirectory?string"build"The directory where the application is built. This should match the buildDirectory directory in your vite config.
serverBuildFile?string"index.js"The server output filename. This should match the serverBuildFile filename in your vite config.
vite?InlineConfigConfigure vite server in development mode.
static?StaticOptionsConfigure static plugin options in production mode
getLoadContext?(context: Context) => AppLoadContext | PromiseA function that returns the value to use as context in route loader and action functions.

getLoadContext usage

In Elysia:

new Elysia()
    .use(
        await reactRouter({
            getLoadContext: () => ({ hotPostName: "some post name" }),
        })
    )
    .listen(port, console.log);

declare module "react-router" {
    interface AppLoadContext {
        hotPostName?: string;
    }
}

In React Router:

import { useLoaderData } from "react-router";
import type { Route } from "./+types/posts._index";

export const loader = async ({ context }: Route.LoaderArgs) => {
    return {
        ...context,
        posts: [
            {
                slug: "my-first-post",
                title: "My First Post",
            },
            {
                slug: "90s-mixtape",
                title: "A Mixtape I Made Just For You",
            },
        ],
    };
};

export default function Posts() {
    const { posts, hotPostName } = useLoaderData<typeof loader>();

    return (
        <main>
            <h1>Posts</h1>
            <p>🔥🔥 {hotPostName} 🔥🔥</p>
            <ul>
                {posts.map((post) => (
                    <li key={post.slug}>
                        <p>{post.title}</p>
                    </li>
                ))}
            </ul>
        </main>
    );
}

Using with Remix

The remix function is deprecated and will be reworked in future versions. Please use reactRouter for better compatibility and features. [More info on remix vs react-router v7] (https://remix.run/blog/incremental-path-to-react-19)

The remix function has the same options and types as reactRouter. Example usage:

Install
bun i elysia-remix@latest @remix-run/node@latest
import { Elysia } from "elysia";
import { remix } from "elysia-remix";

new Elysia()
    .use(await remix())
    .get("/some", "Hello, world!")
    .listen(3000, console.log);

[!IMPORTANT] The Remix functionality will be reworked in future versions, as Remix plans to release a new reworked version of the framework with new ideas under the old name Remix.

Re-exports

import { remix } from "elysia-remix";
import { reactRouter } from "elysia-remix/react-router";
import { reactRouter } from "elysia-react-router";
import { remix } from "elysia-react-router/remix";

Keywords

FAQs

Package last updated on 06 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc