- First, we'll need to open the App.js file and import the dependencies we'll be using:
import React, { Component } from 'react';import axios from 'axios';import { Alert, ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, SafeAreaView,} from 'react-native';
- We'll define the App class with a state object that has three properties. The title and body properties will be used for making the request, and results will hold the API's response:
const endpoint = 'http://jsonplaceholder.typicode.com/posts';export default class App extends Component { state = { results: '', title: '', body: '', }; const styles = StyleSheet.create({ // Defined later }); }
- After saving a new post, we will request all of the posts from the API. ...