Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
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

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;

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

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

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<Counter />);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Few things are missing on your Counter class component, see below:

class Counter extends Component {
   // You need to call the Component constructor so the class Counter inherit 
   // the React Component properties and methods
   constructor(props) {
     super(props);
     // You need to add the state to 'this' so you can reference it later
     this.state = {
       count: 1
     };
   }
  
  // Create the function before you call it, that is why I move
  // it at the top of the render
  formatCount() {
    const {count} = this.state;
    return count === 0 ? 'Zero' : count;
  }
  
  render() {
     return (
     <div>
        <span>{this.formatCount()}</span>
     </div>);
  }
}

// This is fine as long as you have a div with id of root
ReactDOM.render(<Counter />, document.getElementById("root"));

Hope that helps

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this:

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

const root = ReactDOM.createRoot(document.getElementById("root")).render(
  <React.StrictMode>
    <Counter />
  </React.StrictMode>);

React.StrictMode is a tool for highlighting potential problems in an application, StrictMode does not render any visible UI. It activates additional checks and warnings for its descendants. see https://reactjs.org/docs/strict-mode.html for more information.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda