Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react render after data loaded

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 :: how to compare elements in an array 
Javascript :: convert string to uppercase 
Javascript :: normalize method javascript 
Javascript :: js get day name from date 
Javascript :: jquery find 
Javascript :: react port 
Javascript :: javascript list has item 
Javascript :: js how to filter only real numbers from decimals 
Javascript :: array reverse in javascript 
Javascript :: add checkbox dynamically in javascript 
Javascript :: javascript check if string contains special characters 
Javascript :: live vue js port number 
Javascript :: call button click event in javascript 
Javascript :: async await javascript stack overflow 
Javascript :: memory leak in javascript 
Javascript :: get current file name javascript 
Javascript :: create a loop that runs through each item in an array 
Javascript :: javascript create node from innerhtml 
Javascript :: Send Post Fetch REquest With Django 
Javascript :: javascript get main color from image 
Javascript :: Number of documents in Mongodb 
Javascript :: add eslint dependencies for cypress 
Javascript :: swap two variables javascript 
Javascript :: clear the command prompt node 
Javascript :: polyfill for bind 
Javascript :: sum values in array javascript 
Javascript :: using / for division is deprecated and will be removed in dart sass 2.0.0 
Javascript :: js unspecified parameters 
Javascript :: p5js import typescript 
Javascript :: js remove last character 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =