在useRef()钩子内的 React 功能组件中声明静态变量与简单地将它们声明为对象属性有什么优点或缺点。
useRef 方法:
import React, { useRef } from "react";
const MyComponent = () => {
const staticProp = useRef("Hello, World!");
return (
<div>{staticProp.current}</div>
)
}
export default MyComponent;
对象属性方法:
import React from "react";
const MyComponent = () => {
return (
<div>{MyComponent.staticPro}</div>
)
}
MyComponent.staticProp = "Hello, World!";
export default MyComponent;
慕工程0101907
相关分类