Understanding Dynamic React components with cloneElement and React.Children
Hey guys, i am following a tutorial from Meta Front End course on coursera and trying to understand lab example they had on creating dynamic react components.
What code basically does is creating radio group component and radio option component that can accepts childrens and props.
Most of the code i understood, but what puzzles me right now is why we need to include repeating props of:
in in radio option component:
As far as i understood we already assign and modify whatever children is inside of RadioGroup element through adding additionals props like:
in RadioGroup component:
If i remove checked = {checked} , i am losing ability to choose only one option, but i don't understand why. RadioGroup should clone and map over each child component (being Radio Options) give it checked prop and assign value to it being either true or false depending if selected value is equal to its props.value.
I dont really understand the point of adding checked = {checked} and why it doesn't work without it.
What code basically does is creating radio group component and radio option component that can accepts childrens and props.
Most of the code i understood, but what puzzles me right now is why we need to include repeating props of:
in in radio option component:
As far as i understood we already assign and modify whatever children is inside of RadioGroup element through adding additionals props like:
in RadioGroup component:
If i remove checked = {checked} , i am losing ability to choose only one option, but i don't understand why. RadioGroup should clone and map over each child component (being Radio Options) give it checked prop and assign value to it being either true or false depending if selected value is equal to its props.value.
I dont really understand the point of adding checked = {checked} and why it doesn't work without it.


