未处理的拒绝 (TypeError):setState 不是函数

Unhandled Rejection (TypeError): setState is not a function

我有这个错误

Unhandled Rejection (TypeError): setUsers is not a function

这是什么,以及我如何获取

const { users, setUsers } = useState([]);

  const fetchUsers = async () => {
    const data = await fetch("https://randomuser.me/api/?results=10");
    const json = await data.json();
    setUsers(json);
  };

我在控制台中查看数据没有问题,但是当我尝试更新状态时出现问题。

你必须这样做:

const [ users, setUsers ] = useState([]);

const fetchUsers = async () => {
    const data = await fetch("https://randomuser.me/api/?results=10");
    const json = await data.json();
    setUsers(json);
};

因为useState() returns一个数组。