Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to update specific key of an object in reducer

case COMPLETE_TODO: {
  const index = state.todos.findIndex(todo => todo.id === action.payload); //finding index of the item 
  const newArray = [...state.todos]; //making a new array 
  newArray[index].completed = true//changing value in the new array 
  return {   ...state, //copying the orignal state  
          todos: newArray, //reassingning todos to new array 
         }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery public function 
Javascript :: app.router.navigate reset framework7 
Javascript :: js array reduce 
Javascript :: react native full screen view video player 
Javascript :: foreach and replace item based on condition 
Javascript :: modal example react native 
Javascript :: js how to to attach an event handler only once 
Javascript :: how to assign empty function in react component props 
Javascript :: js addeventlistener keyup not working on phone 
Javascript :: waypoint 
Javascript :: How to remove CSS file using JavaScript 
Javascript :: axios post data vue js 
Javascript :: javascript export multiple function 
Javascript :: confetti canvas 
Javascript :: es6 modules node 
Javascript :: mongoose connections 
Javascript :: js get data url of pdf 
Javascript :: js after settimeout 
Javascript :: require("readline") noe js 
Javascript :: java.lang.IllegalArgumentException: Can only download HTTP/HTTPS 
Javascript :: capitalize first letter of a string 
Javascript :: persistent bugger javascript code 
Javascript :: fullscreen api 
Javascript :: Device detector in react js 
Javascript :: sequelize documentation 
Javascript :: how to host a react website 
Javascript :: multiple image upload react 
Javascript :: what is vue.js 
Javascript :: jade cdn 
Javascript :: switch new date getday javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =