useEffect 被执行两次
import React, { useState, useEffect } from "react";
export default function StateFunction() {
const [num, setNum] = useState(1);
useEffect(() => {
console.log("@");
});
return <div>这是一个函数组件 - {num}</div>;
}
// 然后每次刷新, @都会被打印两次
import React, { useState, useEffect } from "react";
export default function StateFunction() {
const [num, setNum] = useState(1);
useEffect(() => {
console.log("@");
});
return <div>这是一个函数组件 - {num}</div>;
}
// 然后每次刷新, @都会被打印两次
2022-05-09
举报