1.3.2 • Published 3 years ago

react-debugger-hook v1.3.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

react-debugger-hook

A hook that easily injects values to react apps through a user friendly console.

Live example: https://react-debugger-hook.netlify.app

This is designed for those who want to review a react project, being able to interact with things like: colors, styles, animations settings, run the app in different mode, and more... React-debugger-hook allows you to have an easy to use console where the reviewer can input values (text, colors, ...) directly into your app.

Install

npm i -S react-debugger-hook

Usage

In this example, just by initializing these two variables, an "Open" button on the left side of the screen will be shown.

When you click on that button, an input console on right side will be opened. There the reviewer can inject those values directly into your react app.

// src/App.js
import { ReactDebuggerProvider, ReactDebuggerConsole } from 'react-debugger-hook'
import ComponentToDebug from './ComponentToDebug';

function App() {
   return (
    <ReactDebuggerProvider>
      {process.env.NODE_ENV !== 'production' && <ReactDebuggerConsole />}
          <ComponentToDebug />
    </ReactDebuggerProvider>
  );
}

export default App;
// src/ComponentToDebug
import { useDebuggerHook } from 'react-debugger-hook'

const ComponentToDebug = () => {
  const color = useDebuggerHook('color', '#fff')
  const yourName = useDebuggerHook('Your name', 'John')

  return (
    <div style={{color}}>
    {`Hello from ${yourName}`}
  </div>)
}

export default ComponentToDebug

API

useDebuggerHook

import { useDebuggerHook } from 'react-debugger-hook'

const ComponentToDebug = () => {
  const currentValue = useDebuggerHook(key, initialValue)

  return (
    <div>
    {currentValue}
  </div>)
}
currentValue: String | the value that can be injected and changed through the console.

key: String | the name of the property to change, this is shown into the console. Choosing a meaningful name is recommended.

initialValue: String | the initial value.

ReactDebuggerProvider, ReactDebuggerConsole

import { ReactDebuggerProvider, ReactDebuggerConsole } from 'react-debugger-hook'
import ComponentToDebug from './ComponentToDebug';

function App() {
   return (
    <ReactDebuggerProvider>
      <ReactDebuggerConsole />
      <ComponentToDebug />
    </ReactDebuggerProvider>
  );
}
ReactDebuggerConsole: ReactComponent | renders the console.

ReactDebuggerProvider: ReactComponent | Provides the context consumed by the hook.

License

MIT

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago