Skip to content

[enhance] - no need to use AsyncStorage #10

Description

@windduong

we can use NativeModules.SettingsManager.settings.RCTDevMenu.isDebuggingRemotely instead of AsyncStorage

import { useCallback, useEffect } from 'react';

import { NativeModules, DevSettings, Platform } from 'react-native';

export const useRemoteDebugger = () => {
  const connectToRemoteDebugger = (value: boolean) => () => {
    NativeModules.DevSettings.setIsDebuggingRemotely(value);
  };

  const handleAddMenuItem = useCallback(() => {
    // Check if remote debugging is enabled
    const isDebuggingRemotely =
      !!NativeModules?.SettingsManager?.settings?.RCTDevMenu
        ?.isDebuggingRemotely;

    setTimeout(() => {
      if (Platform.OS === 'ios') {
        DevSettings.addMenuItem(
          isDebuggingRemotely ? '(*) Stop Debugging' : '(*) Debug JS Remotely',
          connectToRemoteDebugger(!isDebuggingRemotely)
        );
      } else {
        DevSettings.addMenuItem(
          '(*) Debug JS Remotely',
          connectToRemoteDebugger(true)
        );
        DevSettings.addMenuItem(
          '(*) Stop Debugging',
          connectToRemoteDebugger(false)
        );
      }
    }, 100);
  }, []);

  useEffect(() => {
    if (__DEV__) {
      handleAddMenuItem();
    }
  }, [handleAddMenuItem]);
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions