Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react creating function to call API in app: calling APIs after render w error message

import { useState } from 'react';

function App() {
  const [imageUrl, setImageUrl] = useState('https://images.dog.ceo/breeds/hound-afghan/n02088094_1003.jpg');

  return (
    <div>
      <h1>My Dog Log</h1>
      <div>
        <button onClick={() => { console.log("The button was clicked!"); }}>Get New Random Dog Image</button>
        <img src={imageUrl} alt="A random dog" />
      </div>
    </div>
  );
}
Source by learn-2.galvanize.com #
 
PREVIOUS NEXT
Tagged: #react #creating #function #call #API #calling #APIs #render #error #message
ADD COMMENT
Topic
Name
3+8 =