Connecting App.js and React's HTML
P粉716228245
P粉716228245 2023-09-10 00:26:11

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粉716228245
P粉716228245

reply all(1)
P粉396248578

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
Popular topics
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!