Skip to content

dolfbarr/react-log-hook

Repository files navigation

React Log Hook Screenshot

NPM Version License minzipped size dependency count Build Status Last Commit

πŸͺ΅ React Log Hook
Lightweight & customizable logging hook for your react components lifecycle



πŸͺ΅ react-log-hook

React hook for logging per component lifecycle

Features

  • πŸͺΆ Lightweight β€” under 1.5Kb gzipped
  • πŸ—‚οΈ Typed β€” made with TypeScript, ships with types
  • πŸ₯° Simple β€” don't worry about any changes in your props & state
  • πŸ”§ Customizable β€” work in progress πŸ˜‰
  • πŸ”¬ Tested β€” up to 100% coverage
  • 🏎️ Fast β€” native react hooks & optimized
  • πŸ“­ No dependecies

Install

With npm

npm install react-log-hook

With yarn

yarn add react-log-hook

Usage

import {useLog} from 'react-log-hook' const App = () => { // Add a logger const {log} = useLog() const [state, setState] = useState(null) // Log the changes via console in real time! log(state) return null }

FAQ

Will it deep copy the value to make sure it will persist in the logs?

  • πŸŽ‰ Yes, πŸͺ΅ react-log-hook deep copies the value to make sure it will not be changed in the logs later

Do i need to install @types/react-log-hook as well?

  • πŸ’ͺ No, πŸͺ΅ react-log-hook comes with prebundled types

Will it run in production evironment?

  • βœ… By default πŸͺ΅ react-log-hook will run only in dev or development node evironments defined by NODE_ENV

Roadmap

  • Add previous state checking
  • Use object copy to persist in time
  • Use console groups to handle all the logs
  • Add dev environment support by default
  • Polish the looks with component names, function calls, time etc
  • Add more customization options
  • Support SSR & Server components

Contributing

  • 🌟 Stars & πŸ“₯ Pull Requests are welcome for sure! ❀️

Development

πŸͺ΅ react-log-hook uses npm & npm scripts in development, the following scipts can be handy:

npm run start:demo

Starts a demo app with enabled hook to check it in real environment

npm run storybook

Starts storybook with example components to test against

npm run release:check

Combination of linting, type-checking & tests; runs as precommit hook

License

MIT License