Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

redux update item in array

case 'SOME_ACTION':
   return { 
       ...state, 
       contents: state.contents.map(
           (content, i) => i === 1 ? {...content, text: action.payload}
                                   : content
       )
    }

-------------------------------------------------------------
function handleChange(value) {

  const updateArray = userVotes.map(
    (item, i) => item.id === id ? {...item, score: value}
    : item
  )
  setUserVotes(updateArray)

}
 
PREVIOUS NEXT
Tagged: #redux #update #item #array
ADD COMMENT
Topic
Name
8+3 =