React Props
React Props
React Props
React Props are like function arguments in JavaScript and attributes in HTML.
To send props into a component, use the same syntax as HTML attributes:
Example
function Car(props) {
Run Example »
ADVERTISEMENT
Pass Data
Props are also how you pass data from one component to another, as parameters.
Example
Send the "brand" property from the Garage component to the Car component:
function Car(props) {
function Garage() {
return (
<>
</>
);
root.render(<Garage />);
Run Example »
If you have a variable to send, and not a string as in the example above, you just put the variable
name inside curly brackets:
Example
function Car(props) {
function Garage() {
return (
<>
</>
);
root.render(<Garage />);
Run Example »
Or if it was an object:
Example
function Car(props) {
function Garage() {
return (
<>
</>
);
root.render(<Garage />);