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

I don't see output of component in React App

I am new to react, I made a simple component and render some data into this component but I don’t see any output on the browser and I am getting this error on the console "react_dom_client__WEBPACK_IMPORTED_MODULE_1__.render is not a function".

index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
// import App from './App';
// import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.css';
import Counter from './components/counter';

ReactDOM.render(<Counter />, document.getElementById("root"));
// registerServiceWorker();

counter.jsx

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, {Component} from 'react';

class Counter extends Component {
    state = {
        count : 1,
    }
    render() {
        return (
        <div>
            <span>{this.formatCount()}</span>
        </div>
        );
    }

    formatCount() {
        const {count} = this.state;
        return count === 0 ? 'Zero' : count;
    }
}

export default Counter;

>Solution :

You need to create a root and then render with it:

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<Counter />);
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