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.

Unable to work with Redux

See original GitHub issue

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, { 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:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Chathulacommented, May 15, 2017

Ok just fixed it… using this…

const reduxDevtools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__() && window.__REDUX_DEVTOOLS_EXTENSION__();
const composeEnhancers = reduxDevtools || compose;


const store = () => createStore(reducer, exampleInitialState, composeEnhancers);
0reactions
ozluycommented, Mar 12, 2018

check this repo it guess I made a nice configuration https://github.com/ozluy/play-with-nextjs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting | Redux
This is a place to share common problems and solutions to them.
Read more >
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 >

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