react-docgen icon indicating copy to clipboard operation
react-docgen copied to clipboard

Better documentation on resolvers

Open austincondiff opened this issue 7 years ago • 2 comments

I am trying to write a script to generate markdown from the generated JSON output. I have reviewed the documentation for parse() and I am trying to use the findAllComponentDefinitions resolver similar to react-docgen ./myfile.js --resolver findAllComponentDefinitions -o ./docs in the command line. This is what I attempted, but it doesnt work.

const componentAPI = reactDocs.parse(data, reactDocs.findAllComponentDefinitions)
const markdown = generateMarkdown(components[i], componentAPI)

The current documentation does not seem very clear to me.

austincondiff avatar Jan 24 '18 18:01 austincondiff

Hi @acondiff -- I had the same issue, and had to dig around in the source code to find something that worked.

The resolvers are exposed on a property called "resolver":

const reactDocs = require('react-docgen')
const resolvers = reactDocs.resolver

I think you can get your stuff working if you change your first line to this:

const componentAPI = reactDocs.parse(data, reactDocs.resolver.findAllComponentDefinitions)

sea-witch avatar Apr 13 '18 16:04 sea-witch

Thanks a bunch for this. Made a PR to update the docs with this info (and fix the broken description in the table): https://github.com/reactjs/react-docgen/pull/328

maciej-gurban avatar Feb 18 '19 15:02 maciej-gurban