Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhance] - no need to use AsyncStorage #10

Open
windduong opened this issue Jul 22, 2024 · 0 comments
Open

[enhance] - no need to use AsyncStorage #10

windduong opened this issue Jul 22, 2024 · 0 comments

Comments

@windduong
Copy link

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

import { useCallback, useEffect } from 'react';

import { NativeModules, DevSettings } 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(() => {
      DevSettings.addMenuItem(
        isDebuggingRemotely ? '(*) Stop Debugging' : '(*) Debug JS Remotely',
        connectToRemoteDebugger(!isDebuggingRemotely)
      );
    }, 100);
  }, []);

  useEffect(() => {
    if (__DEV__) {
      handleAddMenuItem();
    }
  }, [handleAddMenuItem]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant