Open In App

Remix Introduction & Installation

Remix JS is a Full Stack React-based framework that allows you to render code on the server which tends to result in better performance and Search Engine Optimization as compared to using React on the client-side. But Next Js already provides Server Side Rendering than how it is different from Next Js. Remix Js only supports server-side rendering. It lacks Next Js’ capability for Static Site Generation and Incremental Static Regeneration. It provides faster development as compared to Next Js because it uses esbuild rather than webpack.

Key Features of Remix JS:



Steps to install and run Remix JS Application :

Step 1: Before creating Remix Application make sure you have node.js and npm installed. You can install node js from here. Confirm the installation by running these commands.

npm -v
node -v

Step 2: Now create a new folder and navigate to it in the terminal. Run the following command to create a Remix app with its latest version.



npx create-remix@latest

Step 3: As you proceed with the installation, you will be prompted to select a server. Continue by selecting a server that you are familiar with.

Terminal Screenshot

Step 4: Enter the programming language you would like to use (Javascript/TypeScript) and continue with the installation.

Terminal Screenshot

Step 5: When we open our project in the code editor, we see a fairly straightforward project structure. For now, we will only focus on the app folder as it contains most of our applications. We’ll take things a step further by adding some basic routes to our project. Remix Js supports file-structure-based routing, which implies that any file in your routes directory can be accessed using its relative path to the routes directory. Create a new folder named users in the routes directory, and then two new files in that folder called index.jsx and $id.jsx.

Project Structure:

Example: Here, index.jsx file will contain a component which will be rendered when you navigate to localhost:3000/users. And $id.jsx is a dynamic route . If you’re familiar with Next Js, you might know that for dynamic routes, we use the subscript operator in the filename (Eg : [id].js). It’s a little different here. If you put a $ sign in front of the route name ($id.jsx), it will be considered a dynamic route. And, to access the dynamic id, Remix Js provides us with a hook called useParams(). 

/app/routes/users/index.jsx file :




const Users = () => {
    return (
      <h1>All Users</h1>
    )
  }
    
  export default Users

/app/routes/users/$id.jsx file :




import { useParams } from "remix";
  
const User = () => {
  
  // To access all the parameters
  // in the route
  const params = useParams();
  
  // Destructuring id from params.
  const id = params.id;
  
  return <h1>User with id : {id}</h1>;
};
  
export default User;

Step to run the application: Open the terminal and type the following command.

npm run dev

Output:


Article Tags :