question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Template component can't be connected with Redux anymore?

See original GitHub issue

I am getting error

Could not find “store” in either the context or props of “Connect(Base)”. Either wrap the root component in a <Provider>, or explicitly pass “store” as a prop to “Connect(Base)”.

while connecting template component with redux. This seems like it worked in previous version.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Template component connects to Redux successfully.

Current Behavior

Getting error: Could not find "store" in either the context or props of "Connect(Base)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(Base)".

If I wrap root component with <Provider> from 'react-redux`, it throws error that it expects object, not a function.

Steps to Reproduce (for bugs)

store.js

const initStore = (initialState = {}) => {
  createStore(
    combineReducers({ someReducer, otherReducer }),
    initialState,
    composeWithDevTools(
      applyMiddleware(thunkMiddleware),
    ))
}

template.js

class Base extends React.Component {
...
render(){
    return (
      <div>
        {this.props.children}
      </div>
    )
  }
}
...
export default withRedux(Store, mapStateToProps, mapDispatchToProps)(Base)

./pages/index.js

import Template from 'Templates/Base'

export default class Index extends React.Component {
  render(){
    return (
      <Template>
        {'index'}
      </Template>
    )
  }
}

Context

I am wrapping all pages in template component which includes methods and components that are reused among all pages.

Your Environment

Tech Version
next “^3.0.1-beta.20”
node 6.10.2
OS Ubuntu/Linux
browser Chrome 60

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
hugotoxcommented, Aug 30, 2017

withRedux must be used in pages, for all other components including the template you must use connect from react redux See the relevant example: https://github.com/zeit/next.js/blob/v3-beta/examples/with-redux/components/Page.js

0reactions
timneutkenscommented, Aug 30, 2017

Thanks @hugotox ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux-Form is not connected to Router correctly
I am using redux-form and component is connect ed via withRouter . I tried to workaround it with changing to React.Component , but...
Read more >
Can't reference containers wrapped in a Provider or ... - GitHub
I can't seem to reference anything wrapped in a and a connect // test let component = shallow( ); component.find('#abc'); // returns null ......
Read more >
React Redux connect(): When and how to use it
Cover when and how to use the React Redux connect() API to create container components that are connected to the Redux state.
Read more >
Adding A Robust Form Validation To React Redux Apps
So how do you do form-validation in React Redux apps? ... Update Container Component: Replace “connect” function from redux w/ the one from...
Read more >
Redux Fundamentals, Part 3: State, Actions, and Reducers
We recommend using the Redux templates for Create-React-App as the ... has to update the todos-related state - it's not nested any more!...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found