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

Why does my React Portal shows a Blank Page?

this is my index.html

  <div id="root"></div>
  <div id="portaltest"></div>

this my App.js

  import React, { Component } from "react";
import PortalTest from "./PortalTest";

export class App extends Component {
  render() {
    return (
      <div>
        <PortalTest />
      </div>
    );
  }
}

export default App;

this is what’s in PortalTest.js

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

import React from "react";
import { ReactDOM } from "react";

function PortalTest() {
  return ReactDOM.createPortal(
    <div>This is the PORTAL DIV</div>,
    document.getElementById("portaltest")
  );
}

export default PortalTest;

This suppose to show the contents of PortalTest.js instead it only returns a blank page.
What did I do wrong?

>Solution :

Use import ReactDOM from 'react-dom' instead of import { ReactDOM } from 'react' and it should work.

See this sandbox.

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