Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML renders in the browser but not with ReactHtmlParser #82

Open
iquasere opened this issue Jan 19, 2021 · 2 comments
Open

HTML renders in the browser but not with ReactHtmlParser #82

iquasere opened this issue Jan 19, 2021 · 2 comments

Comments

@iquasere
Copy link

Greetings!

I have a React app, where I am trying to render an HTML file using

import React, { useState } from 'react';
import ReactFileReader from 'react-file-reader';
import {DashboardLayout} from '../components/Layout';
import {Button, Toolbar, Typography} from "@material-ui/core";
import ReactHtmlParser from 'react-html-parser';

const Main = () => {
  const [image, setImage] = useState('')

  let fileReader;

  const handleFiles = files => {
    const file = files.item(0);
    fileReader = new FileReader();
    fileReader.onloadend = handleFileRead;
    fileReader.readAsText(file);
    }

  const handleFileRead = (e) => {
    const content = fileReader.result;
    console.log(content)
    setImage(content)
  }

  return (
    <>
      <ReactFileReader handleFiles={handleFiles} fileTypes={[".xlsx",".html", ".txt"]} >
        <Button
          variant='contained'
          color='secondary'
        >
          Upload results
        </Button>
      </ReactFileReader>

      <>{ ReactHtmlParser(image) }</>

    </>
  )
}

const LoadResults = () => {
  return (
    <DashboardLayout>
      <Toolbar>
        <Typography variant="h6">MOSCA results page</Typography>
      </Toolbar>
      <Main />
    </DashboardLayout>

  )
}

export default LoadResults;

where image is the raw content of the HTML, and it is giving me the error Warning: validateDOMNesting(...): <html> cannot appear as a child of <div>.. I am sharing the files I tried to render. This code worked in rendering the working.html file, but not the not_working.html

@akhi9
Copy link

akhi9 commented Feb 3, 2021

@wrakky @iquasere Is there a workaround/fix for this?

@iquasere
Copy link
Author

iquasere commented Feb 3, 2021

I have still not been able to solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants