小编The*_*que的帖子

更新状态(对象数组)后,React 不会刷新

cards在我的州显示地图功能。状态如下所示:

[{ position: "0", state: "pending" }, 
{ position: "1", state: "pending" }, 
{ position: "2", state: "pending" }]
Run Code Online (Sandbox Code Playgroud)

在一个函数中,我将“状态”从“待定”更改为“正确”,但它不会刷新页面上的任何内容。

export const Card: React.FC<ICardOwnProps> = ({ }) => {
    const [rollingCards, setRollingCards] = useState<IRollingCard[]>([{ position: "0", state: "pending" }, { position: "1", state: "pending" }, { position: "2", state: "pending" }])

    const handleClick = () => {
        let newArray = rollingCards;
        newArray.splice(0, 1)
        setRollingCards(newArray);
    }

    useEffect(() => { console.log("check changes") })

    return (
        <StyledCard className="Card">
            {rollingCards.map((v, i, a) …
Run Code Online (Sandbox Code Playgroud)

javascript state reactjs

4
推荐指数
1
解决办法
4554
查看次数

标签 统计

javascript ×1

reactjs ×1

state ×1