npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-usedebuglog

v1.0.8

Published

Use Javascript console.log as hook

Downloads

16

Readme

react-usedebuglog

react-usedebuglog.png

Get Started

yarn add react-usedebuglog

Usage

First, import DebugLogProvider in your app root:

// index.js

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import DebugLogProvider 'react-usedebuglog'

ReactDOM.render(
  <DebugLogProvider dev={process.ENV.NODE_ENV === 'development'}>
    <App />
  </DebugLogProvider>,
  document.getElementById('root')
)

Then, import useDebugLog in your component:

// App.js

import { useDebugLog } from 'react-usedebuglog'

function App() {
  const c = useDebugLog('App')
  c.log('Hello, World')

  return (
    <div>
      ...
    </div>
  )
}

References

DebugLogProvider props:

  • dev: Boolean, required. Set as true to enable logs by default in your components. Default: false.

useDebugLog arguments:

const c = useDebugLog(<componentName>, <colors>, <enable>)
  • componentName: String, required. Your current component name. Ex: 'MyComponent'.
  • colors: Object, optional. Customize label color and background color. By default, { color: 'inherit', backgroundColor: 'blue'}.
  • enable: Boolean, optional. Enable logs within current component. By default, if enable has no value, it will take dev props value from DebugLogProvider, otherwise enable will locally override dev value.

Examples

const c = useDebugLog('MyComponent')
const c = useDebugLog('MyComponent', false)
const c = useDebugLog('MyComponent', { color: 'white', backgroundColor: 'gray' })
const c = useDebugLog('MyComponent', { color: '#32a852', backgroundColor: '#000000' }, true)
const c = useDebugLog('MyComponent', { color: '#32a852' }) // backgroundColor will be 'blue' by default
const c = useDebugLog('MyComponent', { backgroundColor: 'orange' }) // color will be 'inherit' by default

useDebugLog methods:

react-usedebuglog provides those console Javascript methods:

  • log
  • table
  • info
  • error
  • warn
  • trace

Examples

c.log('Hello, World')
c.table({ a: 'Hello', b: 'World' })

Please refer to console documentation if needed https://developer.mozilla.org/en-US/docs/Web/API/Console

Command

Can by useful in production environment. Assuming you've disabled logs within the entire app by setting dev as false or you've locally disabled by doing const c = useDebugLog('MyComponent', false), you can manually enable logs in a mounted component directly from your web browser console:

useDebugLog.<componentName>(<enable>)

Example:
useDebugLog.MyComponent(true)   // To enable logs within this component
useDebugLog.MyComponent(false)  // To disable logs within this component
  • enable: Boolean, true by default.