React From Scratch, Book 2: Hooks and forms
React From Scratch, Book 2: Hooks and forms
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.2.1 Things covered in Chapter 1: Simplest app
- 0.2.2 Things covered in Chapter 2: Serving React from a CDN
- 0.2.3 Things covered in Chapter 3: Build React apps locally without webpack
- 0.2.4 Things covered in Chapter 4: What is JSX
- 0.2.5 Things covered in Chapter 5: Components and props
- 0.2.6 Things covered in Chapter 6: Assets in React
- 0.2.7 Things covered in Chapter 7: JSX and styling
- 0.2.8 Things covered in Chapter 8: Build a static Bootstrap layout
- 0.2.9 Things covered in Chapter 9: Looping over data
- 0.2.10 Things covered in Chapter 10: The very basics of data and events in React
- 0.2.11 Things covered in Chapter 11: Conditional rendering
- 0.2.1 Things covered in Chapter 1: Simplest app
- 0.3 What this book is about?
- 0.1 Disclaimer
- Chapter 1: Understanding the useState hook
- 1.1 Updating a component’s state using the useState hook
- 1.1.1 Using an object to set state with the useState hook
- 1.1.1 Using an object to set state with 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.5.1 Error: Objects are not valid as a React child
- 2.5.1 Error: Objects are not valid as a React child
- 2.6 The proper way of updating the state object in React
- 2.6 Adding the age input
- 2.6.1 Function expressions as shorthand methods with the computed properties syntax
- 2.6.2 Using computed properties to simplify the event-handling function in forms
- 2.6.1 Function expressions as shorthand methods with the computed properties syntax
- 2.7 Controlled components in React
- 2.8 Other form inputs: radio buttons, checkboxes, textareas, and selects
- 2.8.1 Radio buttons
- 2.8.2 Checkboxes
- 2.8.3 Improving radio buttons and checkboxes
- 2.8.3 Textareas
- 2.8.4 Selects
- 2.8.5 Form submission and preventDefault
- 2.8.1 Radio buttons
- 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
- 2.1 Forms in React
- 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
- 3.1 Render a list of pre-defined todos in a state variable
- Chapter 4: Popular form libraries
- 4.1 Formik
- 4.2 React Hook Form
- 4.3 Yup
- 4.4 Conclusion
- 4.1 Formik
- Chapter 5: Components and keys
- 5.1 Rendering components: a revision
- 5.2 The usage of keys in React
- 5.2.1 Keys must only be unique among siblings
- 5.2.2 Keys used within arrays should be stable
- 5.2.3 Keys should be chosen wisely
- 5.2.4 Keys should be passed to the elements inside the array
- 5.2.5 Keys should not be based on the index of the array
- 5.2.6 Keys should be unique
- 5.2.7 Keys should be strings
- 5.2.8 Keys don’t get passed to your components
- 5.2.1 Keys must only be unique among siblings
- 5.3 Why keys?
- 5.3.1 Can I use the index of the array as a key?
- 5.3.1 Can I use the index of the array as a key?
- 5.4 An example of the problem with keys
- 5.5 Fixing the problem with keys
- 5.6 Conclusion
- 5.1 Rendering components: a revision
- Chapter 6: Popular component libraries
- 6.1 React Bootstrap
- 6.2 Chakra UI
- 6.3 Material-UI
- 6.4 Conclusion
- 6.1 React Bootstrap
- Chapter 7: The useEffect hook
- 7.1 Side effects
- 7.2 Pure and impure functions in React
- 7.3 How to deal with side effects in React
- 7.4 Understanding the dependency array
- 7.5 Using the useEffect hook
- 7.5.1 Using the useEffect hook to log to the console
- 7.5.2 Using the useEffect hook to update the document’s title
- 7.5.3 Using the useEffect hook to update the DOM
- 7.5.2 Using the useEffect hook to update the document’s title
- 7.5.4 Using the useEffect hook to fetch data from the web
- 7.1 Side effects
- Chapter 8: Build an improved todo app
- 8.1 The app’s requirements
- 8.2 Implementing the app
- 8.3 The app’s code explained
- 8.3.1 The App component
- 8.3.2 The TodoForm component
- 8.3.3 The TodoList component
- 8.3.1 The App component
- 8.4 Summary
- 8.1 The app’s requirements
- Chapter 9: Working with the useReducer hook
- 9.1 A very simple useReducer example
- 9.2 Comparing the useState and useReducer hooks
- 9.3 Analyzing the reducer function
- 9.4 Why use useReducer instead of useState
- 9.5 Example 2: Using useReducer to manage multiple state variables
- 9.6 Example 3: Using useReducer to manage multiple state variables, and to manage state that is related to each other
- 9.7 Why I prefer the useReducer hook over the useState hook
- 9.8 An example with multiple different state variables using the useReducer hook
- 9.9 An example with 25 different action types using the useReducer hook
- 9.1 A very simple useReducer example
- Chapter 10: Working with custom hooks
- 10.1 What are custom hooks?
- 10.2 Creating a custom hook
- 10.3 Using a custom hook
- 10.4 Using state in a custom hook
- 10.5 Using effects in a custom hook
- 10.6 Using multiple hooks in a custom hook
- 10.7 Using a custom hook in a component
- 10.8 Using multiple custom hooks in a component
- 10.9 A practical example
- 10.10 Conclusion
- 10.1 What are custom hooks?
- Chapter 11: Build and deploy a portfolio app
- 11.1 The app’s structure
- 11.2 The app’s components
- 11.3 The header component
- 11.3.1 The logo component
- 11.3.2 The menu component
- 11.3.3 The hero component
- 11.3.4 The App component
- 11.3.1 The logo component
- 11.1 The app’s structure
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.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 million USDwriting, 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