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>;
}