React From Scratch, Book 2: React and TypeScript
React From Scratch, Book 2: React and TypeScript
Build your porfolio with hooks and forms
About the Book
This book picks up where Book 1: The Basics left off. In this book, you continue discovering the ins and outs of React.
The focus of this book is working with hooks and forms, as well as further understanding components and JSX.
In this book, you'll:
- build a to-do app
- learn about popular form libraries
- learn about popular component libraries
- build a portfolio app
- deploy your portfolio app to Netlify
Once you've completed this book, you'll be well-equipped to take the next step, which is discussed in Book 3: Context and Redux.
Table of Contents
- Chapter 0: Before we start
- 0.1 Disclaimer
- 0.2 Assumptions: Things to have and know before we start
- 0.3 What this book is about?
- Chapter 1: Understanding the useState hook
- 1.1 Updating a component’s state using the useState hook
- Chapter 2: Forms in React
- 2.1 Forms in React
- 2.2 Watch for input changes in React
- 2.3 Detecting and handling the
onChange
event on an input
- 2.4 Adding the built-in event object
- 2.5 Adding state to the form input
- 2.6 The proper way of updating the state object in React
- 2.7 Controlled components in React
- 2.8 Other form inputs: radio buttons, checkboxes, textareas, and selects
- 2.9 The useRef hook, controlled and uncontrolled components
- 2.10 The useRef hook, focus and blur
- 2.11 The useRef hook, scrollIntoView
- 2.12 The useRef hook, setInterval and clearInterval
- 2.13 The useRef hook, requestAnimationFrame and cancelAnimationFrame
- 2.14 The useRef hook, file input use case
- 2.15 Using the useRef hook to create custom hooks
- Chapter 3: Build a todo app
- 3.1 Render a list of pre-defined todos in a state variable
- 3.2 A form to add new todos
- 3.2.1 Adding the form
- 3.3 Handling the submission of a new todo
- 3.4 Improvements to the app
- 3.5 Exercise and recap
- 3.6 Conclusion
- Chapter 4: Testing your todo app
- 4.1 Planning for testing: a general outline of steps
- 4.2 Implementing our tests
- 4.3 Run the tests
- 4.4 The updated app with passing tests
- 4.4 Red-green-refactor: Conquering your todo app with confidence
- 4.5 Red-Green-Refactor Cycle example in TodoList.test.js
- 4.6 Continuing testing: Refine and Expand
- 4.7 Conclusion
- Chapter 5: Test-Driven Development (TDD) with React: Building a Todo App
- Step 1: Setting up the project
- Step 3: Implementing the App component
- Step 3.1: Declare state for todos using the useState hook
- 3.2: Intermission: Tracking it with git
- Step 3.3: Implement the addTodo function
- Step 3.4: Render the TodoForm and TodoList components
- Chapter 6: Popular form libraries
- 6.1 Formik
- 6.2 React Hook Form
- 6.3 React-hook-form vs Formik
- 6.4 Yup
- 6.5 Conclusion
- 6.6 One more point
- Chapter 7: Components and keys
- 7.1 Rendering components: a revision
- 7.2 The usage of keys in React
- 7.3 Why keys?
- 7.4 An example of the problem with keys
- 7.5 Fixing the problem with keys
- 7.6 Conclusion
- Chapter 8: Popular component libraries
- 8.1 React Bootstrap
- 8.2 Chakra UI
- 8.3 Material-UI
- 8.4 Conclusion
- Chapter 9: The useEffect hook
- 9.1 Side effects
- 9.2 Pure and impure functions in React
- 9.3 How to deal with side effects in React
- 9.4 Understanding the dependency array
- 9.5 Using the useEffect hook
- Chapter 10: Comparing hooks: useRef vs useEffect
- 10.1 Scroll to top of page: useRef vs useEffect
- 10.2 Log to console: useRef vs useEffect
- 10.3 Update the document’s title: useRef vs useEffect
- 10.4 Updating the DOM in React: useRef vs useEffect
- 10.5 Fetching data from the web in React: useRef vs useEffect
- 10.6 Trigger animation: useRef vs useEffect
- 10.7 Toggle visibility: useRef vs useEffect
- 10.8 Capture user input: useRef vs useEffect
- 10.9 Validate form: useRef vs useEffect
- 10.10 Timer countdown: useRef vs useEffect
- 10.11 Conclusions
- Chapter 11: Build an improved todo app
- 11.1 The app’s requirements
- 11.2 Implementing the app
- 11.3 The app’s code explained
- 11.4 Coding a new Todo app from scratch
- 11.5 Todo App, v3
- 11.6 Summary
- Chapter 12: Working with custom hooks
- 10.1 What are custom hooks?
- 12.2 Creating a custom hook
- 12.3 Using a custom hook
- 12.4 Using state in a custom hook
- 12.5 Using effects in a custom hook
- 12.6 Using multiple hooks in a custom hook
- 12.7 Using a custom hook in a component
- 12.8 Using multiple custom hooks in a component
- 12.9 A practical example
- 12.10 Why even bother with a custom useFetch hook?
- 12.11 Conclusion
- Chapter 13: Working with the useReducer hook
- 13.1 A very simple
useReducer
example
- 13.2 Comparing the
useState
anduseReducer
hooks
- 13.3 Analyzing the
reducer
function
- 13.4 Why use
useReducer
instead ofuseState
- 13.5 Example 2: Using
useReducer
to manage multiple state variables
- 13.6 Example 3: Using
useReducer
to manage multiple state variables, and to manage state that is related to each other
- 13.7 Why I prefer the
useReducer
hook over theuseState
hook
- 13.8 An example with multiple different state variables using the
useReducer
hook
- 13.9 An example with 25 different action types using the
useReducer
hook
- 13.1 A very simple
- Chapter 14: Build and deploy a portfolio app
- 14.1 The app’s structure
- 14.2 The app’s components
- 14.3 The header component
- 14.4 The portfolio component
- 14.5 The about component
- 14.6 The contact component
- 14.7 The footer component
- 14.8 The social media component
- 14.9 The App component
- 14.10 Adding the specific content
- 14.11 Styling the app
- 14.12 Update the menu so that it leads to a specific section
- 14.13 Smoothly scrolling to a section when the menu is clicked
- 14.14 Adding images to the Portfolio component
- 14.15 Using site-wide variables
- 14.16 Deploying the App
- 14.17 Other minor tweaks
- Chapter 0: Before we start
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them