How do I connect my index.html to App.js (React)?
<div class="content"> <form action="v2/v2.html" class="form"> <label for="user">Nama</label> <input type="text" name="user" id="user" /> <button type="button" id="load-app">Load App</button> </form> </div> <script src="v3-website/src/App.js"></script>
So when I click the button I want it to go directly to App.js Can someone tell me how to do this?
I used anchor
tag but it doesn't work
P粉3962485782023-09-10 19:49:05
Yes, you can use Javascript CustomEvent
to communicate between React virtual DOM and Javascript real DOM.
Please refer to the following code snippet.
const MyEvent = { on(event: string, callback: (e: any) => void) { document.addEventListener(event, (e: any) => { const data = (e as { detail: any }).detail callback(data) }) }, dispatch(event: string, data ? : any) { document.dispatchEvent(new CustomEvent(event, { detail: data })) }, remove(event: string, callback ? : (e: any) => void) { if (callback) { document.removeEventListener(event, callback) } }, } export default MyEvent