Unable to work with Redux
See original GitHub issuei tried to implement next.js with redux.but it is not working. why is that? this is what i tried so far…
import React, { Component } from 'react';
import withRedux from 'next-redux-wrapper'
import Header from '../components/layout/header';
import Navbar from '../components/layout/navbar';
import { createStore, bindActionCreators } from 'redux';
const exampleInitialState = {
count: 0
}
const addCounter = (value) => dispatch => {
return dispatch({
type: 'ADD',
payload: value
})
}
const reducer = (state = exampleInitialState, action) => {
switch (action.type) {
case "ADD":
const newCount = state.count + action.payload;
return Object.assign({}, state, { count: newCount });
default:
return state;
}
}
const store = () => createStore(reducer, exampleInitialState);
class Home extends Component {
addCount() {
this.props.addCount();
console.log(store().getState());
}
render() {
return (
<div>
<Header />
<Navbar />
<div className="columns top-container">
<div className="column">
<h1>Count: {this.props.count}</h1>
<button className="button is-primary" onClick={this.addCount.bind(this)}>Click Me</button>
</div>
</div>
<style jsx>{`
.top-container {
background: radial-gradient(ellipse at center, rgba(87,73,214,1) 0%, rgba(70,59,173,1) 100%);
color: #FFF;
padding: 15px;
height: 500px;
max-height: 500px;
}
`}</style>
<style global jsx>{`
body, button, input, select, textarea {
font-family: 'Fira Sans', sans-serif;
}
`}</style>
</div>
)
}
}
const mapStateToProps = (state) => {
return {
count: state.count
}
}
const mapDispatchToProps = (dispatch) => {
return {
addCount : () => bindActionCreators(addCounter(1), dispatch)
}
}
export default withRedux(store, mapStateToProps, mapDispatchToProps)(Home);
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Module not found: Can't resolve 'redux' in React | bobbyhadz
The redux module should NOT be globally installed or be in your project's devDependencies , it should be in the dependencies object in...
Read more >Unable to work with Redux · Issue #1963 · vercel/next.js - GitHub
i tried to implement next.js with redux.but it is not working. why is that? this is what i tried so far... import React,...
Read more >How to deal with failure in Redux connect ? | by Guillaume Wuip
The solution proposed here is to use an intermediary component, called EitherComponent , to handle fallback when needed.
Read more >Why am I unable to access a Redux store in a child React ...
It is connecting, it's just that your userPosts state should actually be under state.post.userPosts , rather than state.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok just fixed it… using this…
check this repo it guess I made a nice configuration https://github.com/ozluy/play-with-nextjs