showing results for - "write a counter with redux"
Lotta
20 Oct 2016
1const INCREMENT = "INCREMENT"; // define a constant for increment action types
2const DECREMENT = "DECREMENT"; // define a constant for decrement action types
3
4// define the counter reducer which will increment or decrement the state based on the action it receives
5const counterReducer = (state = 0, action) => {
6  switch (action.type) {
7    case INCREMENT:
8      return state + 1;
9
10    case DECREMENT:
11      return state - 1;
12
13    default:
14      return state;
15  }
16};
17
18// define an action creator for incrementing
19const incAction = () => {
20  return {
21    type: INCREMENT
22  };
23};
24
25// define an action creator for decrementing
26const decAction = () => {
27  return {
28    type: DECREMENT
29  };
30};
31
32// define the Redux store here, passing in your reducers
33const store = Redux.createStore(counterReducer);
34
Daniele
22 Jan 2021
1import React from 'react';
2
3class Counter extends React.Component {
4  state = { count: 0 }
5
6  increment = () => {
7    this.setState({
8      count: this.state.count + 1
9    });
10  }
11
12  decrement = () => {
13    this.setState({
14      count: this.state.count - 1
15    });
16  }
17
18  render() {
19    return (
20      <div>
21        <h2>Counter</h2>
22        <div>
23          <button onClick={this.decrement}>-</button>
24          <span>{this.state.count}</span>
25          <button onClick={this.increment}>+</button>
26        </div>
27      </div>
28    )
29  }
30}
31
32export default Counter;
33
queries leading to this page
react js redux counter example simple exampleredux counter examlecounter example react reduxreact js redux counter examplereact redux count variablecounter redux exampleredux increment counter examplecounter example using reduxcounter using redux and react jscounter redux example with input tagsimple counter react reduxcounter using react reduxreact redux increment if odd examplecounter example in react native with reduxcounter redux store examplereact manage counter variable using reduxhow to count total count in reducer using react reduxreactjs redux counter exampleredux next counter exampleincreament decrement using reduxhow to count total in reducer using react reduxredux react counterhow to increase the counter of reducer in reactcreate a simple counter using redux in react js react redux count requestreact redux tutorial counterreact redux example countercounter with reduxredux js counterredux app increment and decrement exampleredux counter tutorialreact redux increment decrement exampleredux tutorial countermake counter app react reduxhow to make a redux counter app using hookssimply react redux counter exampleredux react counter exampleredux tutorial countercounter app react reduxincrement and decrement in redux in jsreact redux counter tutorialreact redux increment counterreact redux counter appincreament function in action reactreact redux countercounter in reactjs reduxcounter in reduxreact redux increment counter exampleredux countercounter application react reduxreact counter project using reduxcreate a counter app in reduxcounter example in react reduxhow to add counter in reduxreactjs counter example using reduxcounter using react js and reduxredux redux incremtent decerementa counter using redux in reacthow to make product counter in reduxcounter program in reduxcounter 2b in reduxbuild a counter react reduxcounter application using reduxcounter react redux examplecounter redux tutorialcounter using reduxredux with non counter exampleredux counter examplehow to make a counter app with reduxreact redux counter examplereact counter reduxcounter react reduxredux counter is getting 2b1 in reduxredux counter appreact redux tutorialreact native redux incrementredux js counter examplehow to perform increment in redux statereact redux counterwrite a counter with reduxincrement and decrement in redux without reactreact with redux update counterreact redux counter functional examplereact redux increment if even exampleincreament decrement using redux in reacthow to make a redux counter appreact native redux counter examplesimple redux counter appcounter plus with reduxexample counter reduxcreate counter with react reduxredux simple counter examplecounter app in react reduxreact conter with reduxcounter example in react js using reduxredux store example counterreact redux counter with connectreact reducer countredux js counter without reactcounter app using react reduxsimple react redux counter examplecounter app with reduxreact redux store example countercreate counter in redux reactcounte with reduxwrite a counter with redux