What are the advantages or disadvantages to declaring static variables in a React functional components within a useRef()
hook vs. simply declaring them as an object property.
useRef Approach:
import React, { useRef } from "react";
const MyComponent = () => {
const staticProp = useRef("Hello, World!");
return (
<div>{staticProp.current}</div>
)
}
export default MyComponent;
Object Property Approach:
import React from "react";
const MyComponent = () => {
return (
<div>{MyComponent.staticPro}</div>
)
}
MyComponent.staticProp = "Hello, World!";
export default MyComponent;