I created a functional component MyComponent using hooks. I would like to know if it is fine to pass setState to another function renderList? I tried it works fine but according to hooks docs: Only call Hooks at the top level. Don’t call Hooks inside loops, conditions, or nested functions. Does this case count as calling hook from nested functions?
const MyComponent = (listProps) {
const [state, setState] = useState(false);
return (
<div>
renderList(listProps, setState);
</div>
);
}
renderList(listProps, setState){
return (
<ul>
{
listProps.map(item => {
// call setState() with a value here;
return <li>{item}</li>;
});
}
</ul>
);
}