question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Customize display name of custom hooks

See original GitHub issue

Do you want to request a feature or report a bug?

  • Feature

What is the current behavior?

For toolchains/languages that munge the names of functions, the display of custom hooks in React DevTools is unreadable.

For instance, in ClojureScript we might have a custom hook named <-window that would be compiled into the name my_app$hooks$_LT__window.

What is the ~expected~ desired behavior?

To have the ability to set a displayName-like value on a custom hook to customize it’s name in React DevTools.

A potential solution:

function useSomeReallyLongNameThatIDontWantToShow() {
  // Implement my custom hook
}

useSomeReallyLongNameThatIDontWantToShow.debugName = "useShortName";

useShortName would show up in React DevTools instead of useSomeReallyLongNameThatIDontWantToShow.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React 16.8 / Chrome / macOS 10.13.6

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
orestiscommented, Apr 3, 2019

A follow up - could DevTools use source maps to get the original function name?

0reactions
forivallcommented, Sep 21, 2021

You can set function.name via the following, and it shows up in devtools and stack traces:

    try {
      Object.defineProperty(useCustom, 'name', {
        value: displayName,
        configurable: true,
      });
    } catch (_) {}

(some environments dont make “name” configurable, so that’s why the try/catch is necessary)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create your own custom React Hooks - LogRocket Blog
With custom React Hooks, we can reuse stateful logic easily across ... Underneath it, we'll display the name of the coin accompanied by...
Read more >
Building Your Own Hooks - React
A custom Hook is a JavaScript function whose name starts with ” use ” and that may call other Hooks. For example, useFriendStatus...
Read more >
Is it okay to change the name of the custom React Hook in 3rd ...
FWIW, I have a project where I am using Zustand, and I have three stores to store three different types of data. (Note:)...
Read more >
A custom hook for using display names in the React UI template
A custom hook for using display names in the React UI template ... In Daml, a party is represented by an object with...
Read more >
How to Build Your Own React Hooks: A Step-by-Step Guide
Custom React hooks are an essential tool that let you add special, unique functionality to your React applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found