Socket
Socket
Sign inDemoInstall

babel-plugin-transform-hook-names

Package Overview
Dependencies
53
Maintainers
9
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-hook-names

Babel plugin to add hook names for Preact devtools


Version published
Weekly downloads
51K
increased by0.53%
Maintainers
9
Install size
49.5 kB
Created
Weekly downloads
 

Readme

Source

babel-plugin-transform-hook-names

A babel plugin to automatically infer hook names from your code and show them in the Preact Devtools extension.

Before:

Screenshot of Preact devtools without this plugin

After:

Screenshot of Preact devtools with this plugin

Requires: Babel >= 7.12

Usage

Install babel-plugin-transform-hook-names in your project:

npm install --save-dev babel-plugin-transform-hook-names
# or via yarn
yarn add -D babel-plugin-transform-hook-names

Then add it to your babel configuration:

{
	"plugins": ["babel-plugin-transform-hook-names"]
}

How does it work?

The way it works is that each hook is wrapped with a function that is passed the same name as the variable:

Input:

// Works for "preact/compat" or "react" too
import { useState, useReducer, useRef } from "preact/hooks";

function Foo() {
	const [text, setText] = useState("hello");
	const [counter, increment] = useReducer(c => c + 1, 0);
	const rootElement = useRef();
	const memo = useMemo(() => text.toUpperCase(), ["text"]);
}

Output:

import { addHookName } from "preact/devtools";
import { useState, useReducer, useRef } from "preact/hooks";

function Foo() {
	const [text, setText] = addHookName(useState("hello"), "text");
	const [counter, increment] = addHookName(
		useReducer(c => c + 1, 0),
		"counter",
	);
	const rootElement = addHookName(useRef(), "rootElement");
	const memo = addHookName(
		useMemo(() => text.toUpperCase(), ["text"]),
		"memo",
	);
}

License

MIT, see the LICENSE file

Keywords

FAQs

Last updated on 22 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc