I want to pass data to child component after getting data from API, if I remove the child component its working
const parentComponent= (props) => {
const [loans, setLoans] = useState({});
useEffect(() => {
axios.get(`api`).then((result) =>{
let { data } = result;
console.log('result', result)
setLoan(data);
});
}, []);
return(
<ChildComponent data={loans} />
)
}
You are not setting the to the state loans. You have to use setLoans instead of setLoan.
Check this, it should work now.
const parentComponent= (props) => {
const [loans, setLoans] = useState({});
useEffect(() => {
axios.get(`api`).then((result) =>{
let { data } = result;
console.log('result', result)
setLoans(data);
});
}, []);
return(
<ChildComponent data={loans} />
)
}
const [loans, setLoans] = useState({}); use setLoan or changed name after console.log. You have done setLoans which is not equal to setLoan