[React JS] Passing data from child to parent issue


I am building a hangman game and I would like to check if the word to be guessed is confirmed by the player or not using the method onClick. There is 2 buttons : “Yes” and the second “No”. When I check the data value in the child component, I can see it updated but when I check it from the parent component, I am not able to see something from the child.

I have tried 2 different ways :

  • Use value which brings me tons of errors
  • Use 2 functions with 2 different setState which look like the best approach when I checked how I could possibly solve this issue.

Unfortunately, I am kind of stuck right now. That is why I am asking for help :slight_smile:

Here are the two main files : parent, child

Thanks in advance for your help.

P.S.: Excuse me for my english, it is not my native language. Do not hesitate to correct me if I have made mistakes :wink:

hey @FrenchFlair


i dont think you can use onClick as a prop because its reserved , try changing it to something else

I changed it and nothing new happened. I have console.log it and the value is still undefined.

I have already chosen a “reserved” name onSubmit(for the word choice) and it worked.

I would like to add few things:

  • I can access to the state in the child and it updates perfectly
  • The data does not come up to the parent that is why I have an undefined value.

Any ideas?