I've noticed a couple of ways of achieving seemingly the same thing inside a React functional component. When you have what is essentially a config value that is only needed inside this component (Just a constant value, never passed in or modified) You could just use a regular const
or you could store it in the component's state.
Standard variable:
function Example1() {
const a = 1
return <div>{ a }</div>
}
Stored in state:
function Example2() {
const [a] = useState(1)
return <div>{ a }</div>
}
I get the impression that behind the scenes this would lead to Example1 creating a variable on each render and then disposing of it, while Example2 will create the variable once and maintain it until the component is unloaded. Is that accurate? And is one of these methods preferable in terms of performance/good practice?