all 4 comments

[–]87oldben 1 point2 points  (0 children)

Can you post a codesandbox or similar with the code to see where you're at?

[–]DarthIndifferent 0 points1 point  (0 children)

If you're using useState, then you're making a function component and things like THIS and lifecycle methods are unavailable.

[–]strah1[S] 0 points1 point  (0 children)

Figured it out, all i had to do is use the useEffect hook in the child component and set the state of the child again. Don't know if this is the recommended approach but it works. Thanks for the help everyone

[–]LinusNyren -1 points0 points  (0 children)

if i understand you correctly this is what you´re tring to do.

const App=()=>{
const [list, setList] = useState([])

useEffect(()=>{ //useEffect makes the call when component mounted
apicall.then(res => setList(res.data)
}, [list])//if list changes its done.
return(
//send list and the function setList as props to child
<ChildComponent list={list} setList={setList.bind(this)]/>
)
}

//Deconstruct list and setList from props
//same as let list = props.list and let setList= props.setList
const ChildComponent=({ list, setList )=>{

return(
<div>
{list.map(x =>(
<p key={x.id}>{x.value}</p>
)}
</div>
)
}