redux example using stateful component
tschnoelzer opened this issue · comments
Timo Schnoelzer commented
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
Matheus Lima commented
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);
Timo Schnoelzer commented
Thanx Mat ... that was fast ;-) ... I checked that preact usage is similar ... perfect!