Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Next.js React Component won't allow HTML in "export default" function

I’ve defined a Next.js (TypeScript/React) as follows:

'use client'
import React, { FunctionComponent } from 'react';
import { Uploader } from "uploader";
import { UploadButton } from "react-uploader";
import * as fs from 'fs';

const uploader = Uploader({
    apiKey: "free" // Get production API keys from Bytescale
  });
  
const options = { multi: true };

export default function Certificates() {
    return (
        <h1>Certificate Management</h1>
        <UploadButton uploader={uploader}
                  options={options}
                  onComplete={files => alert(files.map(x => fs.readFileSync(x.fileUrl, 'utf-8')).join("\n"))}>
        {({onClick}) =>
          <button onClick={onClick}>
            Upload Certificate...
          </button>
        }
      </UploadButton>
    );
}

As far as I can tell, I am doing everything correctly. But VSCode complains about the HTML in the function’s return statement, and the app won’t build. I’ve never in the past encountered a problem with exporting HTML from a component.

Why is it giving me this error? Am I missing a library?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should return to single element, you can modify in this way

return (<>
         <h1>Certificate Management</h1>
         <UploadButton uploader={uploader}
                  options={options}
                  onComplete={files => alert(files.map(x => 
                  fs.readFileSync(x.fileUrl, 'utf-8')).join("\n"))}>
           {({onClick}) => <button onClick={onClick}>
                           Upload Certificate...
                         </button>}
         </UploadButton>
      </>
    );
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading