search

Home  >  Q&A  >  body text

Connecting App.js and React’s HTML

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粉716228245P粉716228245503 days ago464

reply all(1)I'll reply

  • P粉396248578

    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
    

    reply
    0
  • Cancelreply