Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react render after fetch

import React, { useState } from "react";
import ReactDOM from "react-dom";

const CurrentComponent = () => <div>I am current</div>;
const NewComponent = () => <div>I am new</div>;

const App = () => {
  const [loading, setLoading] = useState(true);

  // this simulates your fetch
  setTimeout(() => {
    setLoading(false);
  }, 2000);

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Component:</h2>
      {loading ? <CurrentComponent /> : <NewComponent />}
    </div>
  );
};

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript remove query string from url 
Javascript :: lowercase to uppercase in javascript 
Javascript :: javascript string normalize method 
Javascript :: firebase.database.ServerValue.TIMESTAMP 
Javascript :: mongoose unique validator 
Javascript :: discord chatbot 
Javascript :: regular expression characters 
Javascript :: jquery post 
Javascript :: how to use axios get 
Javascript :: Converting string to json object 
Javascript :: create new angular project with specific version 
Javascript :: merge 2 json objects js 
Javascript :: nodemailer, mailer, nodemailer npm 
Javascript :: leaflet circle get bounds 
Javascript :: how to export a constant in javascript 
Javascript :: print element by xpath javascript 
Javascript :: list of higher-order functions javascript 
Javascript :: moment timezone set clock in another timezone 
Javascript :: react native paper modal background 
Javascript :: leap year function javascript 
Javascript :: how to clear node modules folder from your computer 
Javascript :: mongo mongoose join aggregation lookup 
Javascript :: getfullyear javascript 
Javascript :: javascript check if object is null or empty 
Javascript :: react native vector icons 
Javascript :: drupal 9 get nid from node 
Javascript :: javascript how to take off a decimal 
Javascript :: node -r dotenv/config 
Javascript :: javascript remove some words list from string 
Javascript :: sequelize operators 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =