React 19 is the latest version of the popular JavaScript library for building user interfaces. It comes with new features and improvements that can help you create better and more performant applications. In this tutorial, we will show you how to use React 19 with two popular tools, Vite and Next.js.
Vite is a build tool that is designed to be fast and efficient. It can be used to develop modern web applications using JavaScript, TypeScript, and other languages. Next.js is a popular framework for building React applications that provides features like server-side rendering and static site generation.
In this tutorial, we will show you how to set up a new React 19 project using Vite and then how to integrate it with Next.js for server-side rendering. Let’s get started!
Step 1: Create a new React 19 project with Vite
To start, make sure you have Node.js and npm installed on your machine. You can install them by following the instructions on the official Node.js website.
Next, create a new directory for your project and open a terminal window. Run the following command to create a new React 19 project using Vite:
npx create@vitejs/app my-react-app --template react
This command will create a new React project in a directory called "my-react-app" using the React template provided by Vite. Next, navigate to the project directory:
cd my-react-app
Step 2: Install React 19
Next, you need to install React 19 and React DOM in your project. Run the following command in your terminal:
npm install react@19 react-dom@19
This will install React 19 and React DOM in your project. You can now start using the latest version of React in your application.
Step 3: Create a simple React component
Now that you have set up your project, let’s create a simple React component to test everything is working correctly. Create a new file called "App.js" in the "src" directory of your project and add the following code:
import React from 'react';
const App = () => {
return <h1>Hello, React 19!</h1>;
};
export default App;
Step 4: Update the main file in your project
Next, update the main file in your project to render the new React component we created. Open the "index.js" file in the "src" directory of your project and update it as follows:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));
Step 5: Start the development server
You can now start the development server to see your React 19 project in action. Run the following command in your terminal:
npm run dev
This will start the Vite development server and open your application in the browser. You should see the "Hello, React 19!" message displayed on the screen.
Step 6: Integrate React 19 with Next.js
Next, let’s integrate React 19 with Next.js for server-side rendering. First, install Next.js in your project by running the following command:
npm install next
Next, create a new file called "_app.js" in the "pages" directory of your project and add the following code:
import App from 'next/app';
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />;
}
export default MyApp;
This custom App component will be used by Next.js to render your React components. Next, update the "App.js" file in the "src" directory of your project to export a named component instead of default:
import React from 'react';
export const App = () => {
return <h1>Hello, React 19 with Next.js!</h1>;
};
Finally, update the "index.js" file in the "pages" directory of your project to import and render the new App component we created:
import { App } from '../src/App';
export default function Home() {
return <App />;
}
Step 7: Start the Next.js server
You can now start the Next.js server to see your React 19 project with server-side rendering in action. Run the following command in your terminal:
npm run dev
This will start the Next.js development server and open your application in the browser. You should see the "Hello, React 19 with Next.js!" message displayed on the screen, rendered with server-side rendering.
Congratulations! You have successfully set up a new React 19 project using Vite and integrated it with Next.js for server-side rendering. You can now start building modern web applications with the latest features and improvements offered by React 19. Happy coding!
What VS Code theme does he use?😭
итого просто переделал под nextjs
At least wait for release lil bro
Gre@t video! Are there Examples of Error Handling or Cancelled Requests or Debouncing Requests?
Its really cool!
In vite, how did you set up the GET/POST handlers on the server with such minimal code? Can we get a repo?
remix baked into react19 with just a bunch of made up hooks, nice. waiting for rr7
im missing something with the useOptimistic @ 13:40 – how is the `sending` flag getting set back to false? the text conditionally displayed based on that value no?
Great video! Can we please get a followup on unit testing (with jest & react-testing-library) forms that use the action prop?
just add vite support instead of webpack. it is really annoying to wait 10 seconds evrey time i save changes
When will nextjs 19 be released?
I love the shirt, Lee!
Let's say if the user has made changes in a current page and action saved that change and redirect to some other page where that data needs to be displayed,
Will this work?
save(someData)
revalidatePath("some other page")
redirect("some other page")
Simple, but great video. Thanks Lee ❤
I think one of the things that is not spoken about with regards to "just fetching it from a server component", is fetching from an external API that requires authentication. I think it's a common enough use case, probably more common than a Next.js app itself interacting with a database, and yet no one ever makes examples.
Sorry for asking this, but what theme are you using for VSCODE?
I was curious about the "with Vite" part, but seems like we removed it altogether from package.json??
lol never thought we would be seeing this
more like this please
Hey, how Next.JS stuffs live without SQL or database features?