toggle react js more items code example
Example: 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)