-
Hello everybody. I inaugurate this discussion section because i think I'm not really facing an issue here 🙂 . I'm working on my company component library, and the need of a custom documentation has emerged. For example : types.js : import propTypes from "prop-types"
export const exportedTypes = {
baz: propTypes.bool.isRequired
} Button.jsx : import React from "react"
import propTypes from "prop-types"
import { exportedTypes } from "./types";
export const Button = () => {
return <button>Yolo</button>
}
Button.propTypes = {
...exportedTypes,
foo: propTypes.number.isRequired
} I've seen this large PR #464 from @phated (sorry to ping you here :) ), I'm well using I'm testing with Can someone show me how to make it work ? Thanks ! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
By default it is not enabled. The cli currently also has no way of enabling it. In order to make it work at the moment you would need to write your own script, something along these lines: const docgen = require('react-docgen');
const src = require('fs').readFileSync('src/Button/Button.jsx');
const componentInfo = docgen.parse(src, null, null, { importer: docgen.importers.makeFsImporter() } );
console.log(componentInfo); |
Beta Was this translation helpful? Give feedback.
-
So after checkouting and saw that test suits was 🟢 with importing prop-types, it appears that the So for posterity, correct script is : const docgen = require('react-docgen');
const path = 'src/Button/Button.jsx'
const src = require('fs').readFileSync(path);
const componentInfo = docgen.parse(src, null, null, {
importer: docgen.importers.makeFsImporter(),
filename: path
} );
console.log(componentInfo); and output is 🎉 : { description: '',
displayName: 'Button',
methods: [],
props:
{ baz: { type: [Object], required: true, description: '' },
foo: { type: [Object], required: true, description: '' }
}
} |
Beta Was this translation helpful? Give feedback.
So after checkouting and saw that test suits was 🟢 with importing prop-types, it appears that the
filename
property is indicated in README.md, is indeedhighly recommended
🙂So for posterity, correct script is :
and output is 🎉 :