@Gaurav4604
Posted
Hi! Congratulations on completing the challenge, it looks great π₯³
Iβll be answering your second question, Itβs normal to pass useState to the child component, to let it modify the data as a beginner, But the idea of React, is to build reusable components, which are meant to handle any environment.
(One example is the <input>
component, which itself takes a value, and an onChange function callback, thus the input component is no longer responsible for handling the data, but rather, only displays any changes)
So if you wanted to build a more robust version of RatingCard and ThankCard, You should structure it as follows.
<Rating
rating={rating}
OnRatingChange={(rating) => setRating(rating)}
OnSubmit={(submit)=> setSubmit(submit)}
/>
And in the Rating.jsx file,
const activeHandle = (e) => {
let activeOption = document.getElementsByClassName('active');
for (let option of activeOption) {
option.classList.remove('active');
}
e.target.classList.add('active');
props.onOptionChange(e.target.innerHTML);
}
You can follow similar logic for submit as well.
Now you do not need to pass setState callback into the child component and let the child do the modifications
Hope this was helpful π
Marked as helpful