I have a variable "myVar" (NOT A STATE)
const myComponent = () => {
const [myState, setMyState] = useState(true)
const myVar = false
return <button onClick={() => {myVar = true} >Click here</button>
}
As you know, this way, if an other state change, the component is re-render, then "myVar" is re-initialized...
Below, solutions I found...
SOLUTION 1 : Initialise the variable outside of the component (but not in the component scope)
const myVar = true
const myComponent = () => {
....
}
SOLUTION 2 : declare a component prop (but public)
const myComponent = ({myVar = true}) => {
....
}
What is the regular solution ?