Horje
how to call api on load using hooks in react Code Example
how to call api on load using hooks in react
function User() {
  const [firstName, setFirstName] = React.useState(null);
  const [lastName, setLastName] = React.useState(null);
  
  React.useEffect(() => {
    fetch('https://randomuser.me/api/')
      .then(results => results.json())
      .then(data => {
        const {name} = data.results[0];
        setFirstName(name.first);
        setLastName(name.last);
      });
  }, []); // <-- Have to pass in [] here!

  return (
    <div>
      Name: {!firstName || !lastName ? 'Loading...' : `${firstName} ${lastName}`}
    </div>
  );
}

ReactDOM.render(<User />, document.querySelector('#app'));




Javascript

Related
send as form data with boundry axios Code Example send as form data with boundry axios Code Example
how to refresh a page in javascript Code Example how to refresh a page in javascript Code Example
second level relationships data not found in strapi Code Example second level relationships data not found in strapi Code Example
exemple de modal reactjs Code Example exemple de modal reactjs Code Example
set time slots with date in javascript Code Example set time slots with date in javascript Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7