I'm trying to pass data from the child component to the parent component without using a button or input event. this is what I did and it returns an error. I search for examples or videos but all the examples are with button or input and I'm not sure if it possible to pass data from child to parent without any trigger
ParentComponent = () => {
const [data,setData] = useState({q:'',a:''})
function showdata(d)=>{setData(q:d,a:d)}
return(
<div>
<h1>{data}</h1>
<ChildComponent childPropsData={showdata} />
</div>
)}
ChildComponent = (props) => {
const [childData,setChildData] = useState({que:'how are you?',ans:'fine!'})
props.childPropsData = childData;
}