JSFiddle - React, Tailwind, and code Playground

by airroom

JavaScript

let nextVampireId = 0;
const ADD_VAMPIRE = 'ADD_VAMPIRE';

/* Action Creator */
function addVampire(vamp) {
  /* Action */
  return { 
    type: ADD_VAMPIRE,
    payload: {
      id: nextVampireId++,
      name: vamp
    }
 };
}  

function vampires(state = [], action) {
  switch (action.type) {
    case ADD_VAMPIRE:
      const { id, name } = action.payload;
      return [
        ...state,
        { id, name }
      ]
    default:
      return state;
  }               
}  

console.log(Redux);