admin 管理员组

文章数量: 1184232

题意

useState 的设置方法不会立即反映变化。

问题背景:

I am trying to learn hooks and the useState method has made me confused. I am assigning an initial value to a state in the form of an array. The set method in useState is not working for me, both with and without the spread syntax.

我正在尝试学习 hooks,useState 方法让我感到困惑。我正在为一个状态赋一个数组形式的初始值。useState 中的设置方法对我没有效果,无论是否使用展开语法。

I have made an API on another PC that I am calling and fetching the data which I want to set into the state.

我在另一台电脑上创建了一个 API,我正在调用它并获取我想设置到状态中的数据。

Here is my code:

这是我的代码:

<div ></div>

<script type="text/babel" defer>
// import React, { useState, useEffect } from "react";
// import ReactDOM from "react-dom";
const { useState, useEffect } = React; // web-browser variant

本文标签: method set useState Immediately change