React Hooks In Action: With Suspense and Concurrent Mode by John Larsen
I’d been away from React for a while and noticed that React 18 has just been released. This reminded me of the talk about Concurrent mode (the ability for a render to be interrupted and then restarted if a higher priority task comes along) and Suspense (seamlessly handle data loading notification in the GUI) a while back when I last did React in my day job.
This book is a great guide to modern React. It discusses what hooks are and how they work, and then walks through an example application that uses a number of the standard React hooks. The application feels really realistic and the author explains the needs for the hooks and how to use them really well – useState, useReducer (part of the eternal question of how to handle component state across the application), useEffect and useRef. There is an initial chapter on managing application state which introduces useCallback and then useMemo.
This section then ends with chapters on managing state with the Context Api, creating your own hooks (by putting together existing hooks, and at the same time respecting the Rules of Hooks), and then a discussion of some of the available third party hooks (and React Query).
The shorter part 2 of the book covers Suspense and Concurrent Mode. The former is introduced in a chapter that covers lazy loading and error boundaries, and then there is a chapter on data fetching and how it interacts with Suspense. The last chapter looks at Concurrent Mode and the future of React.
The book is great – it is just the right length and covers the material in a way that answers most of the first level questions. Highly recommended!
Learning GraphQL – Declarative Data Fetching for Modern Web Apps by Eve Porcello and Alex Banks
Using REST to fetch data from a complicated data model feels increasingly like hard work for the client. There are often lots of times when you fetch an object and then need to issue requests for each of the children, wiring the navigation of the object graph by doing a fetch for each edge. It has often felt to me like a single request with more specifics about the navigation of the graph to the desired properties was the way to go and things like OData and GraphQL offer this.
This books is short introduction to GraphQL. It starts by describing where GraphQL fits in, with a discussion of the issues with REST. There’s a very brief introduction to graph theory and then a chapter on the GraphQL language – this covers fragments, mutations and subscriptions (GraphQL is not just for reading data but allows applications to write data, and also allows you to keep listening and be informed when the data changes).
There is a chapter on schemas, and then an example of how to implement a schema using Apollo Server, an open source GraphQL library. The book finishes with chapters on GraphQL clients (particularly Apollo Client) with some focus on their caches. The last chapter covers GraphQL in the real world, discussing things like timeouts and security, as well as community resources you can access.
The book is short, but provides all the information that you need.