Skip to content
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

Could not find "store" in either the context or props & @connect() (redux connected) component #358

Closed
dlim-dlim opened this issue Mar 16, 2017 · 4 comments

Comments

@dlim-dlim
Copy link

dlim-dlim commented Mar 16, 2017

Hi,

Just wanted to see if there is a current solution to render "store" in an @connect() (redux connected) component in the styleguide?

When I view the styleguide, I'm seeing this error:
Invariant Violation: Could not find "store" in either the context or props of "Connect(Footer)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(Footer)".

Here's the export statement in Footer.jsx:

export default connect(mapStateToProps)(Footer);

In the Wrapper component I tried adding a Provider wrapper without any luck:

render() {
    return (
      <Provider store={getStore()}> 
	      <IntlProvider locale='en'>
	        {this.props.children}
	      </IntlProvider>
      </Provider> 
    );
  }

In styleguide.config.js I'm referencing:
resolver: docgen.resolver.findAllComponentDefinitions

I saw this thread but didn't mention "store" #143

Looking to see if anyone has a workable recommendation?

@n1313
Copy link
Collaborator

n1313 commented Mar 17, 2017

Does adding a prop named store to propTypes work?

@roychoo
Copy link

roychoo commented Mar 17, 2017

you can actually wrap the connect component directly in the readme examples.
i had not tried it, but along this lines should be possible

const Provider = require('react-redux').Provider;
const createStore = require('redux').createStore;
const reducers = require('./reducers').default;

let store = createStore(reducers);

<Provider store={store}>
  <Footer />
</Provider>

@dlim-dlim
Copy link
Author

dlim-dlim commented Mar 20, 2017

thanks @n1313 @roychoo. I tried those options and think I'm running into an issue with my webpack setup for the styleguide that is causing the store to not render properly so going to do some debugging there. I find it gets tricky sometimes to find some parity between the webpack setup of your app vs. the webpack setup for styleguidist. If I discover anything outside of the webpack issue that benefits this thread I'll be sure to share here.

@dlim-dlim
Copy link
Author

dlim-dlim commented Mar 22, 2017

Updating the Readme.md file to require the unconnected component worked:

const Footer = require('./Footer').Footer;
<Footer />

Beyond that also added this line to my styleguide.config.js to resolve an issue with generators from Redux Saga:
webpackConfig.entry.unshift('babel-polyfill');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants