Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I apply Next.js to a React project created with create-react-app?

I'd tried to figure out how to use server side rendering (SSR) on my existing react, and I found Next.js which is a SSR framework for React.

Also, there is create-next-app to easily create Next.js app like CRA. As I already have my existing React project, I need to make it compatible with Next.js. But, they have quite different project architecutre.

I attached two architectures of create-next-app and create-react-app each with images below. As Next requires the folder pages, I feel like I need to move my components in that folder, but I'm confused about src and public folder in create-react-app.

Can anyone help me how can I apply Next.js to an existing React app?

create-next-app

enter image description here

create-react-app

enter image description here

like image 898
Jae P. Avatar asked Jan 17 '19 20:01

Jae P.


People also ask

Should I use next JS or create React app?

When you choose Next. js, it offers the best solutions for server-side rendering and static website development. It also makes it easy to manage projects with a variety of tools and features. On the other hand, React is the best choice for developing UIs for one-page applications.

Can I use npm With create React app?

Prerequisites. In order to create React application, you will need to have a Node that is >= 14.0. 0 and npm >= 5.6. As we discussed earlier npm is a package manager that comes with Node.

Can I use npm in next JS?

To add Next.js to your project, you will not need to load the react and react-dom scripts from unpkg.com anymore. Instead, you can install these packages locally using the Node Package Manager: npm .


1 Answers

You can install Next js by adding 'next' package to your CRA. However, you would have to refractor part of your codebase. The src folder should contain a subfolder called 'pages', consisting of your paths.

Visit the Next JS Documentation for more

like image 195
Lavesh Deepak Panjwani Avatar answered Oct 27 '22 16:10

Lavesh Deepak Panjwani