-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for composed component via HoC #143
Comments
|
I'm looking into this right now. It's a real problem with Ideally we shouldn't need to Any ideas would be helpful! |
Also wondering about this as many of our components are wrapped with |
Has anyone tried this using the |
Yeah as HoCs become a popular pattern this is definitely a serious limitation. |
Any other ideas than export a component with some special name? |
My temporary solution is having a directory structure like this:
Where index.js serves as the entry point and the HoC wrapping happens there, thus leaving my-component.jsx unwrapped, and using that in the styleguide instead and manually passing it whatever props the HoC provided. |
I was able to do this on my project, although, it wasn't too pretty. I'm thinking about a way we can support HoC generically in But anyway, here's what I did. I hope it's helpful to some. Using the following, I was able to render an Use the handlers: docgen.defaultHandlers.concat(function (documentation, docPath) {
// Calculate a display name for components based upon the declared class name.
if (docPath.value.type === 'ClassDeclaration' && docPath.value.id.type === 'Identifier') {
documentation.set('displayName', docPath.value.id.name);
// Calculate the key required to find the component in the module exports
if (docPath.parentPath.value.type === 'ExportNamedDeclaration') {
documentation.set('path', docPath.value.id.name);
}
}
// The component is the default export
if (docPath.parentPath.value.type === 'ExportDefaultDeclaration') {
documentation.set('docPath', 'default');
}
}), I then used webpack.resolve.alias to define a mock for redux (specifically for updateWebpackConfig: webpackConfig => {
webpackConfig.resolve = Object.assign(webpackConfig.resolve, appConfig.resolve);
// Mock @connect() components
webpackConfig.resolve.alias['react-redux'] = path.join(__dirname, '/src/util/mockRedux.js');
// ... other stuff ...
return webpackConfig;
} And then mockRedux.js is very simple: export const connect = () => c => c; This mostly works, but it's not ideal, but throwing it out there in case it sparks some more ideas on how to solve this cleanly in this project. |
The "quick fix" in my project was to use a broader resolver, however it has resulted in some console errors being reported in the browser (it's finding duplicate definitions). I've made a note to look into it later (but hoping the issue is resolved sooner). resolver: require('react-docgen').resolver.findAllComponentDefinitions |
I noticed that react-docgen has a pull request recently to add an HOC resolver in the mix. reactjs/react-docgen#124 |
@nhavar yea I noticed that too. Hopefully it gets merged soon so we can close the loop on this issue! 😄 |
First of all thank you for your nice work. The Styleguide is awesome! But I have a problem with a HOC wich wraps my component. I this a known problem? Cheers! |
@hauptrolle Most probably #179. I’d wait a few days for the new version with updated react-docgen — it might be fixed already there. |
@sapegin That would be awesome 👍 Thank you for your fast reply! |
4.0.0 is out! |
Could anyone update the cookbook? I’m afraid I don’t have a good example. |
HoC is a good pattern but when I use it, component are not recognized as such.
Any idea how can we add support for this?
I tried to add
export { SidebarItem }
but no luck :/The text was updated successfully, but these errors were encountered: