0

I have a variable that stores a dynamic state name and would like to do something like this:

function App() {
  const [state, setState] = useState("this is the first state") 
  var stateName = 'setState'

  useEffect(() => {
    stateName("updated state")
  },[])

  return(
    <p>{state}<p>
  )
}
    

Is this possible?

Dean Arvin
  • 115
  • 6
  • 1
    Does this answer your question? [How to execute a JavaScript function when I have its name as a string](https://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string) – Andy Ray Jan 12 '21 at 22:08
  • Please provide more context why you want to do this as opposed to just calling setState("updated state") in the useEffect function – Croc Jan 13 '21 at 07:23

0 Answers0