Can a React component returns null?
Have some custom components wrapping 3rd party lib that has nothing to do with React. Is it possible to get props when a React components returns null?
React component code looks something like this:
import coolLib from 'cool-lib';
export default function MyComponent({ id }) {
useEffect(() => {
const lib = new coolLib({ id });
lib.on('load', () => {
// do stuff
});
return () => {
coolLib.remove()
}
}, []);
return null;
}
MyComponent.propTypes = {
id: PropTypes.string.isRequired
}
If I return <div>{id}</div> or some other JSX then seeing props getting pulled out, but not when return null;, is this use case not supported in react-docgen?
yes it can, did that multiple times. Please rewrite your export default to use memo(MyComponent) for perf
I've originally asked this Q in Storybook js repo and was suggested to ask here: https://github.com/storybookjs/storybook/discussions/15857#discussioncomment-1210046
Returning null skips generating argsTable is storybook, so yes a component can return null but I want to know by retuning null does react-docgen skip getting props for that component or not...
In version 6 it will be possible to use a comment to mark a function as a component with @component.