Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next.js : Refresh page after modifying a file, without rerunning 'npm run'

I've been building websites using a normal LAMP stack with javascript (and jQuery) for the frontend for quite a while. But I wanted to try using javascript for the backend as well. I'm just starting to learn next.js.

On the old way, if I have modified a php file, to see the effect I can just refresh the web browser. But I noticed that with next.js you can't see the change immediately. I have to stop the npm script, rerun the "npm run xxx" command, then refresh the browser. It's kind of time consuming.

Is there a way to automate this process?

like image 369
develobster Avatar asked May 01 '17 14:05

develobster


People also ask

How do I force a refresh on NextJS?

import Router from 'next/router'; Router. reload(); This will force the reload but without the hook, allowing you to do it wherever you need it outside of component function.

Does NextJS have hot reload?

In this article, we will learn about the Fast refresh in the NextJS project. Fast Refresh is a new hot reloading experience that gives you instantaneous feedback on edits made to your React components. It is now enabled by default for all projects on Next. js 9.4 or newer.

What is hot code reloading in next JS?

It's a utility that enables hot reloading on Node-based servers, so that whenever you make a change to a server file and save -- it instantly starts to restart without any prompt from your part. But nodemon doesn't work out of the box with NextJS and requires a small amount of configuration.

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

One common issue that causes this has to do with accidentally importing a component and making a minor typo with lowercase/uppercase naming conventions.

For example, you import a component named Navigation, as navigation.

This will still import Navigation, but the live reloading will be broken.

like image 179
Ben Quirk Avatar answered Sep 22 '22 11:09

Ben Quirk