Skip to Main Content
React Projects
book

React Projects

by Roy Derks
December 2019
Intermediate to advanced content levelIntermediate to advanced
474 pages
10h 3m
English
Packt Publishing
Content preview from React Projects

Loading and displaying the data

Loading and displaying data that is retrieved from a data source is something we did in the previous chapter. This section will explore this further. Follow these steps to get started:

  1. We will start by fetching the project data from the data file. To do this, we need to add the necessary functions to the Board component. We need these to access the React life cycles. These are constructor, where the initial state is set, and componentDidMount, where the data will be fetched:
...class Board extends Component {+ constructor() {+   super();+   this.state = {+     data: [],+     loading: true,+     error: '',+   }+ }+ async componentDidMount() {+   try {+     const tickets = await fetch('../../assets/data.json');+ const ticketsJSON ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React Projects - Second Edition

React Projects - Second Edition

Roy Derks
Test-Driven React

Test-Driven React

Trevor Burnham

Publisher Resources

ISBN: 9781789954937Supplemental Content