Let say i have two components one parent and another child now i have a prop in child component called active which basically assign {active} class to child if its true now i wanted to change this prop from its parent component while rendering. take a look at some codes below
main code
import React from 'react';
import { List , Item } from "../Buttons";
export function Sample2() {
return (
<List>
<Item>items</Item>
<Item>items</Item>
<Item>items</Item>
</List>
)
}
component codes
commented line is what i am trying to achieve but its not allowed
export function List({ children }){
const [index,setIndex] = useState(0)
function getOptions(){
return children.map((each,i)=>{
//each.props.active = index == i
return each
})
}
return (
<div className="list">
{getOptions()}
</div>
)
}
export function Item({ active , children }){
const classes ="item p-4 border-b" + (active?` active`:"")
return (
<div className={classes}>{children}</div>
)
}
now i wanted to know what is the way to achive this or i am not following react flow ? i am old in javascript but very much new to react so please explain what would be the best way to achive this