class Records extends React.Component { static propTypes = { recordsUrl: PropTypes.string }; componentDidMount() { this.fetchRecords(this.props.recordsUrl); } state = { records: [], prevUrl: "", nextUrl: "" }; fetchRecords = url => { fetch(url) .then(data => { if (data.ok) { return data.json(); } throw new Error("Network error!"); }) .then(data => { this.setState({ records: data.records, nextUrl: data.next_url, prevUrl: data.prev_url, }); }) .catch(err => console.log("Error: " + err)); }; ... ... ...