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.

Generate docs for hooks

See original GitHub issue

Since hooks have been released a while back, it would be nice to be able to generate docs for them.

For example, for a simple hook:

import {useState} from 'react';

/**
 * A hook to do something
 *
 * @param {object} params
 * @param {boolean} [params.disabled] Disable the thing
 * @returns {boolean}
 */
const useMyHook = (params) => {
  const [isUsing, setUsing] = useState(false);
  // Some logic here to invoke setUsing()
  return isUsing;
};

export default useMyHook;

There is not way to generate some docs. Or is there and I just can’t find it?

NOTE: I am actually using react-styleguidist which uses this lib to generate component docs.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:16
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
trevordmillercommented, Feb 7, 2020

“Hooks are generally an implementation detail of a component and not part of its public API”

I believe this is true for app projects. But for libraries where custom hooks are a part of the public facing interface, this is often not the case in my experience. For example:

etc.

Our organization has a good amount of custom hooks like these that are a part of libraries we expose publicly. It would be really nice if these could be auto-documented with react-docgen with the rest of our React code. Although technically “just functions” they are still coupled with React so IMO it makes sense to support them in this library.

I would imagine the most common users are using tools like Storybook or react-styleguidist that use react-docgen under the hood, where auto documentation of their hooks would be helpful.

5reactions
dagerikhlcommented, Feb 9, 2021

Valid point.

A JSDoc annotation is an option.

Another option is using the convention that hooks are prefixed by use.... This isn’t consistently reliable, but a pretty well established convention and fronted by the React team, so it might be viable.

Would supporting functions as a whole be another option? Perhaps behind a flag to allow people to opt out of the functionality? Not sure what impact this would have on this library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React hooks documentation generator - Stack Overflow
I'm facing the same issue, and can't generate docs for methods declared inside of a functional component using JSdoc and better-docs in a...
Read more >
Building Your Own Hooks - React
You can write custom Hooks that cover a wide range of use cases like form handling, animation, declarative subscriptions, timers, and probably many...
Read more >
Hooks - Apollo GraphQL Docs
The ApolloProvider component leverages React's Context API to make a configured Apollo Client instance available throughout a React component tree.
Read more >
Automating React Documentation using React-Docgen ⚙️
A few design systems and frameworks use react-docgen as part of their process to generate documentation. Usually you take the object that's output...
Read more >
Automate Your Python Code Documentation with Pre-commit ...
A hands-on guide to automating docstrings checks and auto-generating documentation with pre-commit hooks. Photo by Joshua Aragon on Unsplash.
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