在 React 中如何从状态数组中删除一个元素?

在 React 中从状态数组中删除一个元素:

  • 使用 filter() 方法迭代数组。
  • 在每次迭代中,检查是否满足条件。
  • 将状态设置为过滤器方法返回的新数组。
import {useState} from 'react';

export default function App() {
  const initialState = [
    {id: 1, name: 'Fql', country: 'Austria'},
    {id: 2, name: 'Jiyik', country: 'China'},
  ];

  const [employees, setEmployees] = useState(initialState);

  const removeSecond = () => {
    setEmployees(current =>
      current.filter(employee => {
        //