npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

rn-restart

v1.0.1

Published

πŸ”„ Restart your React Native app programmatically. Production-ready Turbo Module with zero dependencies. Perfect for language changes, theme switching, OTA updates, and more. Works on iOS & Android.

Readme

Why RN-Restart?

Sometimes your React Native app needs a fresh start. Whether you're applying language changes, switching themes, implementing OTA updates, or recovering from errors – RN-Restart provides a simple, reliable way to restart your app programmatically.

Built with modern React Native architecture (Turbo Modules) for optimal performance and future compatibility.

✨ Features

πŸ“‹ Table of Contents

πŸ“¦ Installation

Step 1: Install the package

npm install rn-restart

or with yarn:

yarn add rn-restart

Step 2: Platform setup

iOS

cd ios && pod install

Android
βœ… Auto-linked! No additional setup needed.

πŸ”§ Compatibility

| Platform | Minimum Version | Status | |:--------:|:---------------:|:------:| | React Native | 0.70+ | βœ… | | iOS | 13.0+ | βœ… | | Android | API 21+ | βœ… | | Node.js | 18+ | βœ… |

πŸš€ Quick Start

Basic Usage

import { restart, restartWithCacheClear } from 'rn-restart';

// Simple restart
restart();

// Restart with cache clearing (great for Android)
restartWithCacheClear();

That's it! Just call the function when you need to restart. ⚑

import React from 'react';
import { View, Button, Alert } from 'react-native';
import { restart } from 'rn-restart';

export default function SettingsScreen() {
  const handleRestart = () => {
    Alert.alert(
      'Restart App',
      'Are you sure you want to restart?',
      [
        { text: 'Cancel', style: 'cancel' },
        { text: 'Restart', onPress: () => restart() }
      ]
    );
  };

  return (
    <View>
      <Button title="Restart App" onPress={handleRestart} />
    </View>
  );
}

πŸ’Ό Real-World Use Cases

🌍 1. Language/Locale Change

import { restart } from 'rn-restart';
import AsyncStorage from '@react-native-async-storage/async-storage';
import i18n from 'i18next';

const changeLanguage = async (languageCode: string) => {
  try {
    // Save the new language preference
    await AsyncStorage.setItem('userLanguage', languageCode);
    
    // Update i18n
    await i18n.changeLanguage(languageCode);
    
    // Restart to apply changes throughout the app
    restart();
  } catch (error) {
    console.error('Failed to change language:', error);
  }
};

🎨 2. Theme Switching

import { restart } from 'rn-restart';
import { Alert } from 'react-native';

const switchTheme = async (theme: 'light' | 'dark') => {
  Alert.alert(
    'Restart Required',
    'The app needs to restart to apply the new theme. Continue?',
    [
      { text: 'Cancel', style: 'cancel' },
      {
        text: 'Restart',
        onPress: async () => {
          await AsyncStorage.setItem('theme', theme);
          restart();
        },
      },
    ]
  );
};

πŸ“¦ 3. After OTA Updates

import { restartWithCacheClear } from 'rn-restart';
import codePush from 'react-native-code-push';

const checkForUpdates = async () => {
  const update = await codePush.checkForUpdate();
  
  if (update) {
    await update.download();
    await update.install(codePush.InstallMode.IMMEDIATE);
    
    // Restart with cache clear to ensure clean update
    restartWithCacheClear();
  }
};

πŸ” 4. User Logout

import { restartWithCacheClear } from 'rn-restart';

const logout = async () => {
  try {
    // Clear user data
    await AsyncStorage.clear();
    
    // Clear any cached tokens
    await clearAuthTokens();
    
    // Restart with cache clear for complete cleanup
    restartWithCacheClear();
  } catch (error) {
    console.error('Logout failed:', error);
  }
};

πŸ› 5. Error Recovery

import { restart } from 'rn-restart';
import { ErrorBoundary } from 'react-error-boundary';

const ErrorFallback = ({ error, resetErrorBoundary }) => (
  <View style={styles.container}>
    <Text style={styles.title}>Something went wrong</Text>
    <Text style={styles.error}>{error.message}</Text>
    <Button
      title="Restart App"
      onPress={() => {
        resetErrorBoundary();
        restart();
      }}
    />
  </View>
);

const App = () => (
  <ErrorBoundary FallbackComponent={ErrorFallback}>
    <YourApp />
  </ErrorBoundary>
);

πŸ“š API Reference

restart()

Restarts the React Native application by reloading the JavaScript bundle.

Platform Support: iOS, Android

Returns: void

Example:

import { restart } from 'rn-restart';

restart();

What it does:

  • iOS: Triggers RCTReloadCommand to reload the React Native bridge
  • Android: Restarts the main activity with cleared task flags

restartWithCacheClear()

Restarts the React Native application after clearing cached data.

Platform Support: iOS (network cache only), Android (full app cache)

Returns: void

Example:

import { restartWithCacheClear } from 'rn-restart';

restartWithCacheClear();

What it does:

  • iOS: Clears NSURLCache and reloads the React Native bridge
  • Android: Recursively deletes the app's cache directory, then restarts

πŸ”€ Platform Differences

⚠️ Important Notes

βœ… Perfect For

Language changes β€’ Theme switching β€’ OTA updates β€’ User logout β€’ Error recovery β€’ Config updates

❌ Not For

Navigation resets β€’ State resets β€’ Frequent operations β€’ Background tasks

πŸ†˜ Troubleshooting

App doesn't restart on iOS

Solution: Ensure your app is using the new architecture with Turbo Modules enabled.

# ios/Podfile
use_react_native!(
  :path => config[:reactNativePath],
  :hermes_enabled => true,
  :fabric_enabled => true # Enable new architecture
)

Android app crashes on restart

Solution: Make sure your MainActivity is properly configured:

// MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(null) // Pass null to prevent state restoration
}

Cache not clearing on Android

Solution: Verify your app has proper permissions. The module uses the app's cache directory which doesn't require special permissions, but ensure you're not blocking file operations.

TypeScript types not found

Solution: Ensure your TypeScript configuration includes the module:

{
  "compilerOptions": {
    "moduleResolution": "node",
    "resolveJsonModule": true
  }
}

🎨 Example App

This repository includes a beautiful example app showcasing all features:

git clone https://github.com/abdallaemadeldin/RN-Restart.git
cd RN-Restart
yarn
yarn example ios    # or: yarn example android

What's included:

  • βœ… Standard restart with confirmation
  • βœ… Restart with cache clearing
  • βœ… Delayed restart with countdown
  • βœ… Platform-specific behavior demos
  • βœ… Real-world use case examples
  • βœ… Modern, beautiful UI

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.

πŸ› Found a Bug?

Report it

πŸ’‘ Have an Idea?

Request a Feature

πŸ’¬ Questions?

Start a Discussion

πŸ“„ License

MIT Β© Abdalla Emad Eldin


⭐ Star this repo if you find it useful!

GitHub stars


πŸ“š More Resources

API Documentation β€’ Changelog β€’ Quick Start Guide


Built with ❀️ for the React Native community

Made with create-react-native-library