Answer the question
In order to leave comments, you need to log in
Why is {} put with a function argument?
const StarRating = function({countStar}) {
return(createArray(countStar).map((n,i) => <Star key={i}/>))
}
Answer the question
In order to leave comments, you need to log in
When creating a component, the props object is passed to the function, all jsx attributes of the component are collected in the props object.
Therefore, without parentheses, it will be like this:
const StarRating = function(props) {
return(createArray(props.countStar).map((n,i) => <Star key={i}/>))
}
In other words: an argument arrives in the function, which has the countStar property. In order to immediately operate with what lies in this property, {} is done - destructuring.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question