Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react render component 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 :: react render after data loaded 
Javascript :: how to compare elements in an array 
Javascript :: how make date object in jquery from custom date 
Javascript :: numbered occurences in regex 
Javascript :: string to number 
Javascript :: pass parameter to handleclick react 
Javascript :: angular redirect to external url 
Javascript :: node sass version react 
Javascript :: form submit event get button 
Javascript :: express error middleware 
Javascript :: js sort number array 
Javascript :: javascript datetime format 
Javascript :: babylon js camera position 
Javascript :: promise.all vs promise.allsettled 
Javascript :: descending order in objects in js 
Javascript :: cart page route in shopify 
Javascript :: use setstate in function component 
Javascript :: javascript sort map by value 
Javascript :: how to remove quotes using regex 
Javascript :: push json into json 
Javascript :: math random js 
Javascript :: sort in mongoose aggregate lookup 
Javascript :: get only numbers from string 
Javascript :: how can i convert object to an array javascript 
Javascript :: regex to check 8 < length < 16, one uppercase, one lowercase and must have at least one number and one special character 
Javascript :: search an array with regex javascript filter 
Javascript :: how to redirect in react router v6 
Javascript :: How to print somethign to the console with javascript 
Javascript :: cookie options 
Javascript :: axios get 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =