What is Fast Refresh?
Fast Refresh is a feature that:- Preserves component state during edits
- Only updates the code that changed
- Catches errors during render and displays them in the app
- Works with function components and Hooks
- Provides immediate visual feedback
How It Works
When you save a file, Fast Refresh:- Detects the changed module through Metro bundler
- Re-evaluates that module and its dependencies
- Updates the app without losing component state
- Shows a visual indicator that refresh occurred
HMR Client
Fast Refresh is powered by Metro’s Hot Module Replacement (HMR) system:Enabling Fast Refresh
iOS
- Open Developer Menu: Cmd + D (Simulator) or shake device
- Enable “Fast Refresh”
- The setting persists across app reloads
Android
- Open Developer Menu: Cmd/Ctrl + M (Emulator) or shake device
- Enable “Fast Refresh”
- The setting persists across app reloads
Programmatically
What Gets Refreshed?
Function Components
count state is preserved.
Class Components
State Preservation Rules
Preserved State
State is preserved when you edit:- Component render logic
- Event handlers
- Effects and their dependencies
- Styles
- Non-exported helper functions
Reset State
State resets when you edit:- Exports from the module
- Hook call order
- Hook types (useState → useReducer)
- Component signature changes
Error Recovery
Fast Refresh catches errors and displays them:Syntax Errors
- The error message
- File and line number
- Code frame with the error
Runtime Errors
- Red error screen
- Stack trace
- Error boundary information
Hooks Support
Fast Refresh has first-class support for Hooks:useState
useEffect
Custom Hooks
Limitations
Module Exports
Changing exports causes a full reload:Class Components
Anonymous Functions
Higher-Order Components
Tips for Best Experience
1. Use Function Components
2. Keep Components Small
3. Use Named Exports
4. Extract Complex Logic
Troubleshooting
Fast Refresh not working
Fast Refresh not working
Try these solutions:
- Check that Fast Refresh is enabled in Dev Menu
- Restart Metro bundler:
npm start -- --reset-cache - Reload the app: shake device → “Reload”
- Check for syntax errors in your code
- Verify you’re using function components for best results
State keeps resetting
State keeps resetting
Common causes:
- Changing component props or signature
- Modifying exported constants
- Changing Hook call order
- Using anonymous function components
- HOC wrapping is changing
Full reload happening instead of Fast Refresh
Full reload happening instead of Fast Refresh
This happens when:
- You edit a file that exports non-component values
- You change class component lifecycle methods
- You modify files outside of components (utils, constants)
- Circular dependencies are detected
Performance Impact
Fast Refresh is designed to be fast:- Updates typically complete in < 100ms
- Only changed modules are re-evaluated
- No full app reload required
- State preservation eliminates navigation overhead
Comparison
Developer Settings Integration
Fast Refresh integrates with React Native DevSettings:Next Steps
Debugging
Learn about debugging tools and techniques
Metro
Configure Metro bundler for your project