Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

having written a counter with redux how does it work

const INCREMENT = "INCREMENT"; // define a constant for increment action types
const DECREMENT = "DECREMENT"; // define a constant for decrement action types

// define the counter reducer which will increment or decrement the state based on the action it receives
const counterReducer = (state = 0, action) => {
  switch (action.type) {
    case INCREMENT:
      return state + 1;

    case DECREMENT:
      return state - 1;

    default:
      return state;
  }
};

// define an action creator for incrementing
const incAction = () => {
  return {
    type: INCREMENT
  };
};

// define an action creator for decrementing
const decAction = () => {
  return {
    type: DECREMENT
  };
};

// define the Redux store here, passing in your reducers
const store = Redux.createStore(counterReducer);
Comment

counter using redux

counter with redux
Comment

PREVIOUS NEXT
Code Example
Javascript :: this js 
Javascript :: javascript declare empty array 
Javascript :: post express node js input 
Javascript :: js after settimeout 
Javascript :: select ng-options set default value 
Javascript :: change a css class in javascript 
Javascript :: require("readline") noe js 
Javascript :: d3.js onclick event 
Javascript :: error message to show in label jquery 
Javascript :: node.js upload files 
Javascript :: angular property binding 
Javascript :: how to update json key name while keeping the values in mysql 
Javascript :: getSheetByName 
Javascript :: react native refresh control color 
Javascript :: even.target in javascript 
Javascript :: Device detector in react js 
Javascript :: javascript set value to the largest value in an array 
Javascript :: How to append the string to the current url in jquery | Javascript 
Javascript :: install node specific version ubuntu 
Javascript :: javascript sort multi-dimensional array 
Javascript :: express project structure 
Javascript :: js date format 
Javascript :: ejemplo async await javascript 
Javascript :: switch new date getday javascript 
Javascript :: joi validate 
Javascript :: GET and CHANGE the class of an element 
Javascript :: how to rename zip file nodejs 
Javascript :: double ?? js 
Javascript :: $[name] in jquery 
Javascript :: get latlong of address in here map api javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =