Generate docs for hooks
See original GitHub issueSince 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:
- Created 5 years ago
- Reactions:16
- Comments:11 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.