One minute
Refering to Global jQuery Object From React (With TypeScript)
When you render a React component inside a modal handled by jQuery and would like to be able to handle closing it from there:
<input
type="button"
value="Cancel"
className="button btn-cancel"
onClick={this.handleClose}
/>
You can do this:
private handleClose = (ev: React.MouseEvent<HTMLInputElement>) => {
window.$('#info').dialog('close');
}
This works, but you will get an error from TypeScript compiler:
TS2339: Property '$' does not exist on type 'Window'.
You will need to extend the window interface with your new property:
declare global {
interface Window { $: any } // 'any' isn't ideal but we all know what we have to deal with
}
window.$ = window.$ || {};
Read other posts
comments powered by Disqus