array state react map filter add code example
Example 1: use map with filter in react components from arrays of data
<div>
{names.filter(name => name.includes('J')).map(filteredName => (
<li>
{filteredName}
</li>
))}
</div>
Example 2: filter() array of objects on change react
const handleChange = (e) => {
const id = hospitalsDetails.filter(obj => obj.hospitalName == e.target.value)
setCurrentApp({ ...currentApp, [e.target.id]: e.target.value, ["hospitalID"]: id.hospitalID })
}