0

I'm wondering if it's possible to change this HTML code to make it fit into React.For example is if I try to put this HTML code into the REACT app. I also included the code for Node.js and MongoDB. Does it require a lot of change for the HTML code to make it fit in React? Is it necessary to include script and import DOM in the method to include it in REACT App?

This is home.ejs code use for upload and download files.

<html lang="en">
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <meta http-equiv="X-UA-Compatible" content="ie=edge">
     <title>Document</title>
 </head>
 <body>
     <h2>Upload Files</h2>
        <form action="/" method="POST" enctype="multipart/form-data">
         <input type="file" name="pic"><br>
         <input type="submit" value="Upload">
        </form><br><br><br><br>
    <h2>Download Files</h2>
        <table>
            <thead>
                <tr>
                    <td>
                        image
                    </td>
                    <td>
                        download
                    </td>
                </tr>
            </thead>
            <tbody>
                <% for(var i=0; i < data.length > 0; i++) {%>
                 <tr>
                     <td><img src="<%= data[i].picspath %>" style="width:100px; height:100px;"></td>
                     <td>
                         <form action="/download/<%= data[i]._id %>" method="GET">
                          <input type="submit" value="Download">
                        </form>
                     </td>
                 </tr>
                <% } %>
            </tbody>
        </table>
 </body>
 </html>
1

1 Answer 1

1

sure just follow the following steps

  1. Replace the opening and closing < html > tags with a < div > tag.
  2. Replace the opening and closing < head > tags with a <React.Fragment> tag.
  3. Replace the opening and closing < body > tags with a < div > tag.
  4. Replace the <% and %> tags with curly braces { and } to indicate that the code between them is JavaScript.
  5. Replace the <%= and %>tags with curly braces { and } to indicate that the code between them is an expression that should be rendered as a string.
<div>
<React.Fragment>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>Document</title>
</React.Fragment>
<div>
  <h2>Upload Files</h2>
  <form action="/" method="POST" enctype="multipart/form-data">
    <input type="file" name="pic" /><br />
    <input type="submit" value="Upload" />
  </form>
  <br /><br /><br /><br />
  <h2>Download Files</h2>
  <table>
    <thead>
      <tr>
        <td>image</td>
        <td>download</td>
      </tr>
    </thead>
    <tbody>
      {data.map((item) => {
        return (
         <tr>
          <td>
            <img src={item.picspath} style={{ width: "100px", height: "100px" }} />
          </td>
          <td>
            <form action={`/download/${item._id}`} method="GET">
              <input type="submit" value="Download" />
            </form>
          </td>
        </tr>)
      })}
    </tbody>
  </table>
</div>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you..It really help me to understand how it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.