I want to call a function from a imported component in my parent react component.
My parent component:
import Customer from './Customer';
function App() {
return (
<div className="App">
<Container maxWidth="sm">
<Grid container spacing={2}>
<Grid item xs={6}>
<Button onClick={Customer.showCustomers}>show customers</Button>
</Grid>
</Grid>
</Container>
<Customers />
</div>
);
}
My child component (customer):
function Customer() {
const [showAllCustomers, setshowAllCustomers] = useState(false);
function showCustomers() {
setshowAllCustomers(true);
}
return (
(...)
);
}
How do I call a function from another component in functional react?
Or how do I change the state from another component (if thats the better approach)
All tutorials are about object-oriented react components, unfortunately.