redux-zero / redux-zero

A lightweight state container based on Redux

Home Page:https://matheusml1.gitbooks.io/redux-zero-docs/content/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

redux example using stateful component

tschnoelzer opened this issue · comments

Hi team,

I have difficulties to use redux-zero with a Class based component. need to do as using animation for items and i could not get it working in the stateless manner.

can someone provide to counter.js class rewritten as a class Counter extends Component?

Best and many thanks in advance

Timo

Great question @tschnoelzer, you can do it like this:

import React, { Component } from "react";
import { connect } from "redux-zero/react";

import actions from "./actions";

const mapToProps = ({ count }) => ({ count });

class Counter extends Component {
  render() {
    const { count, increment, decrement } = this.props;
    return (
      <div>
        <h1>{count}</h1>
        <div>
          <button onClick={increment}>increment</button>
          <button onClick={decrement}>decrement</button>
        </div>
      </div>
    );
  }
}

export default connect(
  mapToProps,
  actions
)(Counter);

Thanx Mat ... that was fast ;-) ... I checked that preact usage is similar ... perfect!