Skip to content
Advertisement

Send multiple props across components React

I am trying to send two variables from the Component ‘Game’ to the Component ‘App’ but I am unsure how to send more than one prop at a time.

This what I have:

JavaScript
JavaScript
JavaScript

With this I am able to send the prop ‘score’ from ‘Game’ to ‘App’ but I was wondering if it was possible to send more then just the one prop, such as ‘score’ and a new variable, ‘count’ with the same button press, to ultimately be able to display both ‘score’ and ‘count’ in the ‘Score’ Componenet.

Thanks.

Advertisement

Answer

Sure you can, just update the function you defined in the Parent App component to accept two arguments.

App.js

JavaScript

Game.js //refactored since it doesnt need to use state

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement