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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.