0.3.0 • Published 4 years ago

@pulsovi/react-debug v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Welcome to @pulsovi/react-debug šŸ‘‹

Version License: MIT

provide a hook to debug why and how a component is rerendered

Install

npm install @pulsovi/react-debug

Usage

Simplest usage for function component with some states.

import React, { useState } from 'react';
import useDebug from '@pulsovi/react-debug';

export default function SomeComponentToDebug(props) {
  const [data, setData] = useState([]);
  const [title, setTitle] = useState('empty');

  useDebug({ props, state: { data, title }});

  // ... your code

  return <div>
    <h1>{title}</h1>
    <pre>{JSON.stringify(data, null, 2)}</pre>
  </div>;
}

useDebug can get second parameter for more infos such in elem of list.

import React, { useState } from 'react';
import useDebug from '@pulsovi/react-debug';

export default function SomeComponentToDebug(props) {
  const [value, setValue] = useState(null);

  useDebug({ props, state: { value }}, props.title);

  // ... your code

  return <div>
    <h1>{props.title}</h1>
    <p>{value}</p>
    <aside>{props.details}</aside>
  </div>;
}

It can also be used in class components more easily.

import React from 'react';
import { debug } from '@pulsovi/react-debug';

class SomeComponentToDebug extends React.Component {
  constructor(props) {
    super(props);
    this.state = { clicked: false };
  }

  render() {
    debug(this, this.props.title);

    // ... your code

    return <div>
        <h1>{this.props.title}</h1>
        <p
          onClick={() => { this.setState({ clicked: true }); }}
        >{this.state.clicked ? 'Click me, please.' : 'Bravo !'}</p>
    </div>;
  }
}
export default SomeComponentToDebug;

Author

šŸ‘¤ David GABISON david.gabison@outlook.com

Show your support

Give a ā­ļø if this project helped you!

0.3.0

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago