<Fab raised="true" size="small" color="primary" variant="extended"
onClick={props.Store.fetchFromServer}
and
this.fetchFromServer = async () => {
await console.log('test')
}
works fine.
But when changed to following
<Fab raised="true" size="small" color="primary" variant="extended"
onClick={props.Store.fetchFromServer('test')}
and
this.fetchFromServer = async (val) => {
await console.log(val)
}
throw following error, what I am missing?
Failed prop type: Invalid prop `onClick` of type `object` supplied to `ButtonBase`, expected `function`
this did not help much Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function`
It is failing because once you pass a parameter to the function, you are calling it, and therefore it is now returning a value (and thus becomes an
object
). The way to get around this is by passing an anonymous function into theonClick()
event like so, basically making it into a function:Here is a test example to show you the types of functions being called in different ways: