añadir react a node project

import React, { Component } from 'react';import logo from './logo.svg';import './App.css';class App extends Component {  constructor(){    super()    this.state = {      numero: 0    }    this.handleRandom = this.handleRandom.bind(this)    this.handleRandomType = this.handleRandomType.bind(this)  }  componentDidMount() {    this.handleRandom();  }callApi = async (a) => {    let response;    if(a===undefined){      response = await fetch(`/api/random`);    } else{      response = await fetch(`/api/random/${a}`);    }    const body = await response.json();    if (response.status !== 200) throw Error(body.message);    return body;};handleRandom(){    this.callApi()    .then(res => {      let numero = res.number;      this.setState({ numero: numero })    })    .catch(err => console.log(err));  }handleRandomType(type){    this.callApi(type)    .then(res => {      let numero = res.number;      this.setState({ numero: numero })    })    .catch(err => console.log(err));  }render() {    return (      <div className="App">        <header className="App-header">          <img src={logo} className="App-logo" alt="logo" />          <h1 className="App-title">Números Random</h1>        </header>        <p className="App-intro">        Número random: {this.state.numero}        </p>        <hr/>        <p>          <button onClick={this.handleRandom}>Número Random</button>          <button onClick={ ()=> this.handleRandomType("even")}>Número Random Par</button>          <button onClick={ ()=> this.handleRandomType("odd")}>Número Random Impar</button>        </p>      </div>    );  }}export default App;

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source