MenuItem onClick should have a Typecheck od function
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
when provide a prop with onClick in MenuItem like:
this.handleDialogControl('open', 'dialogPartManage')
a exec funtion, should throw Error
Current Behavior
when I use this to open dialog, and forget to set it as a arrow-function, like
() => this.handleDialogControl('open', 'dialogPartManage')
It will cause a crash that this page will keep loading.
Steps to Reproduce (for bugs)
- create a dialog
- open it with a MenuItem's onClick prop, with some code like:
// handle method
handleDialogControl = (method, boxName) => {
const list = [...this.state.openList];
if (method === 'close') {
const openList = removeFromOpenList(list, boxName, this.enum);
return this.setState({ openList });
}
if (method === 'open') {
list.push(boxName);
return this.setState({ openList: list });
}
return new Error('UserError: params invalid');
}
// use with onClick
<MenuItem onClick={this.handleDialogControl('open', 'dialogAddLink')}>
- then open it in your browser
- unexpected keep loading.
Context
the Error is difficult to find,(also meet) I should provide some suggest, for this case.
Your Environment
| Tech | Version |
|---|---|
| Material-UI | ^1.0.0-beta.16 |
| React | ^16.0.0 |
| browser | chrome at 61.0.3163.100 |
| etc |
Regarding your code I think it's normal, on each render the function is called with a setState inside which will make another render etc ..
If you set an arrow function your function will only be called when an event is fired
so I sugguest a validate, It should be a function, in the PropType required, otherwise being errered for a good Tips I meet this by a miss, there could be other unlucky guys
I can't understand at all what is being described here, but it doesn't seem to have anything to do with TypeScript...
so I sugguest a validate, It should be a function, in the PropType required, otherwise being errered for a good Tips
@CyanGlory This is outside of the scope of Material-UI. It sounds like a React related issue. Maybe it's React how should warn when providing a undefined onClick property.