Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to call react function from external JavaScript file

$
0
0

I have read this post [ https://brettdewoody.com/accessing-component-methods-and-state-from-outside-react/ ]

But I don't understand.

that is not working on my source code.

it's my tsx file

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}}>       ....)

it's my external javascript file

function fn_test(){    window.childComponent.file_input_html(3)    var element = document.getElementById("ifrm_write_file");    // element.value = "mystyle";}

How can i call file_input_html function?

plase help me ...


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>