React Native Debug Toolkit
A simple yet powerful debugging toolkit for React Native with a convenient floating UI for development.
Installation
npm install react-native-debug-toolkit
# or
yarn add react-native-debug-toolkit
Basic Usage
// In your App.js
import DebugToolKit from 'react-native-debug-toolkit';
function App() {
useEffect(() => {
if (__DEV__) {
const debugToolKit = new DebugToolKit();
debugToolKit.addFeature({
name: 'network',
label: 'Network Logs',
setup: () => console.log('Feature ready'),
getData: () => ({ message: 'Hello debugging world!' })
});
debugToolKit.showDebugPanel();
}
return () => {
if (__DEV__) {
DebugToolKit.instance.destroy();
}
};
}, []);
return <YourApp />;
}
Features
- Lightweight floating debug panel
- Customizable debugging features
- Development-only functionality (automatically disabled in production)
- Easy to extend with your own debug tools
API Reference
DebugToolKit
new DebugToolKit()
Initializes a new instance of the debug toolkit. It's a singleton, so multiple calls will return the same instance.
addFeature(feature: Feature): DebugToolKit
Adds a new debugging feature to the toolkit. Returns the toolkit instance for chaining.
Feature object must have:
name
: Unique identifier for the feature
label
: Display name in the debug panel
setup()
: Function to run when the feature is added
getData()
: Function that returns data to display in the panel
cleanup()
: (Optional) Function to run when the feature is removed
showDebugPanel(): void
Shows the floating debug panel.
hideDebugPanel(): void
Hides the floating debug panel.
updateDebugPanel(): void
Updates the debug panel with the latest feature data.
destroy(): void
Cleans up the debug toolkit, removing all features and event listeners.
Example: Network Feature
// In debugFeatures.js
import { NetworkFeature } from 'react-native-debug-toolkit/lib/features/NetworkFeature';
export const createNetworkFeature = () => {
const feature = new NetworkFeature();
return {
name: 'network',
label: 'Network Logs',
setup: () => feature.setup(),
getData: () => feature.getData(),
cleanup: () => feature.cleanup()
};
};
// In App.js
const debugToolKit = new DebugToolKit();
debugToolKit.addFeature(createNetworkFeature());
debugToolKit.showDebugPanel();
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
MIT