Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react dont render component until 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 :: react render component after data loaded 
Javascript :: body-parser deprecated 
Javascript :: normalize javascript 
Javascript :: npm is not recognized 
Javascript :: difference between library and framework in javascript 
Javascript :: js console log multiple 
Javascript :: connect mysql to node js 
Javascript :: functional component how to add to existing array react 
Javascript :: node js run for loop asynchronously 
Javascript :: object.entries 
Javascript :: contains duplicate leetcode solution javascript 
Javascript :: stylesheet create 
Javascript :: gesture handling with react native expo 
Javascript :: how to convert number to character in javascript 
Javascript :: equivalent method load jquery with javascript 
Javascript :: send x-www-form-urlencoded request nodejs 
Javascript :: jquery has parent with class 
Javascript :: .on click jquery 
Javascript :: node js while loop with settimeout 
Javascript :: add json object to json array javascript 
Javascript :: types of loops in javascript 
Javascript :: js increment and decrement function for cart 
Javascript :: queryselectorall 
Javascript :: read json using fs 
Javascript :: nodejs call api 
Javascript :: loadtest node 
Javascript :: concatenate multiple arrays javascript 
Javascript :: reverse string in js 
Javascript :: copy paste menu react native textinput disable 
Javascript :: java script login system 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =