Open In App

Next.js Fast Refresh

Last Updated : 29 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Next.js Fast Refresh provides an instant feedback loop during development by preserving component state and applying changes without a full page reload, making the development process smoother and more efficient.

What is Next.js Fast Refresh?

Next.js Fast Refresh is a development feature that provides instant feedback by updating changes in your code in real-time without losing component state or performing a full page reload, enhancing the efficiency and smoothness of the development process.

Features

  • Automatic Activation: Fast Refresh is enabled by default in Next.js, no extra configuration is needed.
  • Real-Time Updates: Changes to components or styles are applied immediately, maintaining component state and avoiding full page reloads.
  • State Preservation: Fast Refresh retains component state across updates, improving development workflow and reducing the need for manual refreshes.

Create NextJS Application

You can create a new NextJS project using the below command:

npx create-next-app gfg

Project Structure:

All the NextJs applications with version 9.4 or newer come with the Fast refresh feature that gives you instantaneous feedback on edits made to your React components. 

Example: For this example, we will create a new javascript file in our pages directory with the name 'gfg.js' with the below content.

JavaScript
// pages/gfg.js

import React from 'react'

export default function index() {
  return (
    <div>
      <h1>This is File</h1>
    </div>
  )
}

Here we created a simple react component named index and inside this component, we add one heading. Now after running the application if we make any changes in our gfg.js file then the changes will be visible within a second, without losing component state.

Steps to run the application: Run the below command in the terminal to run the app.

npm run dev

Output:


Next Article

Similar Reads