I am trying to get a button component which is nested in my “CharPic” component to update a value in the state of my App component. I have a handleClick function in my App component which changes the state property menuPage to 0 or 1 depending on the name of a “Button” argument.
There is a button in the “CharPic” component:
It should change which components are displayed. I am trying to make it like a menu in a game where you can switch between inventory and battle screens. When I change the state property menuPage manually, it works.
I can’t seem to get the button to do as I want it. This is what I have so far. I am passing the function handleClick as a property to the “CharPic” component.
The “CharPic” component is then passing the handleClick function to the button component it is rendering. This button has an onClick which activates a sendToParent function, which in turn returns handleClick passing the button’s name as an argument.
I feel like the info from sendToParent is not making it all the way up to the main App component and is getting stuck in the “CharPic” component, but I can’t figure out how to send it further along. Any help would be greatly appreciated!