React Refresh

0.18.0 · active · verified Sun Apr 19

React Refresh is the core package that implements Fast Refresh, React's official hot reloading mechanism designed for a superior development experience. This feature allows developers to instantly see changes to React components without losing their local state, significantly speeding up the feedback loop during development. It achieves this by updating only the necessary component code and re-rendering, preserving state for functional components and Hooks. The `react-refresh` package itself, currently at version 0.18.0 (last published in October 2025), provides the underlying runtime and Babel transform. It is primarily consumed by bundler-specific plugins, such as `@pmmmwh/react-refresh-webpack-plugin` for Webpack or `@vitejs/plugin-react` for Vite, rather than being imported directly into application code. It maintains an active release cadence, with updates demonstrating sustainable maintenance. Fast Refresh differentiates itself from older hot-reloading solutions by being officially supported by the React team, offering greater reliability, and prioritizing safe state preservation.

Common errors

Warnings

Install

Imports

Quickstart

This Vite configuration demonstrates how to set up Fast Refresh for a React project using the official `@vitejs/plugin-react`. This plugin transparently integrates `react-refresh` to provide hot module reloading during development.

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// vite.config.ts or vite.config.js
export default defineConfig({
  plugins: [
    react({
      // The `@vitejs/plugin-react` plugin automatically enables Fast Refresh
      // (Hot Module Replacement) for React components by default in development mode.
      // It leverages 'react-refresh' internally. No explicit import of 'react-refresh'
      // or manual Fast Refresh configuration is typically needed directly in the app.
      // 'jsxRuntime: "automatic"' is a common modern setting for React 17+.
      jsxRuntime: 'automatic',
      // 'fastRefresh: true' is the default for development mode in this plugin.
      // You generally don't need to explicitly set it unless overriding.
      fastRefresh: process.env.NODE_ENV !== 'production',
    }),
  ],
  // Ensure the Vite development server is configured for HMR (this is the default behavior).
  server: {
    hmr: true,
  },
  // For TypeScript, if you're using it, ensure your tsconfig.json has 'jsx: "react-jsx"' or 'jsx: "react-jsxdev"'.
  // For example, in tsconfig.json:
  // {
  //   "compilerOptions": {
  //     "jsx": "react-jsxdev"
  //   }
  // }
});

view raw JSON →