【发布时间】:2021-05-07 23:29:59
【问题描述】:
我已阅读这篇文章 [ https://brettdewoody.com/accessing-component-methods-and-state-from-outside-react/ ]
但我不明白。
这不适用于我的源代码。
这是我的 tsx 文件
declare global {
interface Window {
fn_test(): void;
childComponent: HTMLDivElement; <-- what the... ref type????
}
}
export default function Contact(): React.ReactElement {
....
function file_input_html( i:number ): React.ReactElement {
return (
<form id={`frm_write_file_${i}`} .... </form>
)
}
....
return (
<div ref={(childComponent) => {window.childComponent = childComponent}}>
....
)
这是我的外部 javascript 文件
function fn_test(){
window.childComponent.file_input_html(3)
var element = document.getElementById("ifrm_write_file");
// element.value = "mystyle";
}
如何调用 file_input_html 函数?
请帮帮我...
【问题讨论】:
标签: reactjs typescript react-native typescript-typings