Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Axios in a React Native component.
React Native
import [1] from 'axios';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'Axios' which is not the default import name.
Confusing Axios with fetch or http.
✗ Incorrect
The Axios library is imported using the name axios by convention.
2fill in blank
mediumComplete the code to make a GET request to 'https://api.example.com/data' using Axios.
React Native
axios.[1]('https://api.example.com/data') .then(response => { console.log(response.data); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' for fetching data.
Using 'fetch' which is not an Axios method.
✗ Incorrect
To fetch data, use the get method of Axios.
3fill in blank
hardFix the error in the Axios POST request to send JSON data.
React Native
axios.post('https://api.example.com/data', [1]) .then(response => { console.log(response.data); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a JSON string instead of an object.
Passing null or a plain string.
✗ Incorrect
Axios automatically converts JavaScript objects to JSON, so pass the object directly.
4fill in blank
hardFill both blanks to handle errors in an Axios GET request.
React Native
axios.get('https://api.example.com/data') .then(response => { console.log(response.data); }) .[1](error => { console.[2](error.message); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error' instead of 'catch' for error handling.
Using console.error or console.warn instead of console.log.
✗ Incorrect
Use catch to handle errors and console.log to print the error message.
5fill in blank
hardFill all three blanks to create an Axios instance with a base URL and timeout.
React Native
const api = axios.[1]({ baseURL: '[2]', [3]: 5000 });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'create' to make an instance.
Confusing 'timeout' with 'baseURL'.
✗ Incorrect
Use axios.create to make an instance, set baseURL to the API address, and timeout to limit request time.