How to do it...

  1. 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';
  1. 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 
  }); 
}
  1. After saving a new post, we will request all of the posts from the API. ...

Get React Native Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.