Answers for "toggle react js more items"

1

toggle react js more items

import React, {useState} from 'react'

const [toggleItems, setToggleItems] = useState(
  [
    {
    	name: 'First',
      	active: false
    },
    {
    	name: 'Second'
      	active: false,
    }
  ]
)

const toggle = () => {
  setToggleItems(old => old.map(item => {
  		item.active = !item.active
    	return item
  	})
  )
}

console.log(toggleItems)
Posted by: Guest on May-02-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language