Knowledge check: Interacting with the API

Knowledge check: Interacting with the API

  1. Why should you never call hooks inside a nested function in react?

    • Because hooks can only be called from the top level of a function component

    • To ensure that the component updates correctly

    • To avoid unnecessary re-renders of the component

    • To prevent memory leaks

  2. True or false. The fetch function should be used inside the componentDidMount lifecycle method or useEffect hook.

    • True

    • False

  3. When you receive a HTTP response using the fetch() API, how do you parse the data into a JavaScript object?

    • The fetch() API automatically parses the response data as a JSON object.

    • You should use the text() method of the response object to parse the data as a JSON object

    • You should use the json() method of the response object to parse the data as a JSON object.

    • You should use the JSON.parse() method to parse the response data as a JSON object.

  4. Which of the following statements are true? Choose all that apply.

    • You can load local JSON files in your React project

    • The fetch() API call cannot make DELETE request

    • If the external API returns JSON data, you need to exclusively parse it in the fetch() API

    • You cannot make multiple fetch() calls in the useEffect hook

  5. Complete the sentence: JSON is ______________.

    • Only a data exchange format

    • Only a file format

    • A file format and a data exchange format