Micro State Management With React Hooks Anonymous PDF Download
Micro State Management With React Hooks Anonymous PDF Download
Anonymous download
https://ebookbell.com/product/micro-state-management-with-react-
hooks-anonymous-55708694
Micro State Management With React Hooks Explore Custom Hooks Libraries
Like Zustand Jotai And Valtio To Manage Global States Daishi Kato
https://ebookbell.com/product/micro-state-management-with-react-hooks-
explore-custom-hooks-libraries-like-zustand-jotai-and-valtio-to-
manage-global-states-daishi-kato-47756910
https://ebookbell.com/product/stateowned-enterprises-in-a-mixed-
economy-micro-versus-macro-economic-objectives-reprint-mehdi-
haririan-11052188
https://ebookbell.com/product/stateeconomic-reform-and-social-
security-microlevel-experiences-in-indiaaswini-mishra-2010th-edition-
aswini-mishra-60921214
https://ebookbell.com/product/solidstate-physics-fluidics-and-
analytical-techniques-in-micro-and-nanotechnology-madou-5086008
The Micropolitics Of Capital Marx And The Prehistory Of The Present
Jason Read
https://ebookbell.com/product/the-micropolitics-of-capital-marx-and-
the-prehistory-of-the-present-jason-read-46709786
https://ebookbell.com/product/a-multiagent-system-for-adaptive-
control-of-a-flappingwing-micro-air-vehicle-sylvie-adams-
delahunt-37327892
https://ebookbell.com/product/slovenian-politics-and-the-state-miro-
haek-simona-kukovi-56498582
https://ebookbell.com/product/scars-to-pearls-a-medical-healing-and-
spiritual-journey-through-the-phases-of-malignant-melanoma-stage-iiia-
skin-cancer-with-micrometastasis-lita-m-worthington-48906758
https://ebookbell.com/product/statue-marianne-micros-53986406
BIRMINGHAM—MUMBAI
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express or
implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for
any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot
guarantee the accuracy of this information.
Group Product Manager: Pavan Ramchandani Publishing Product Manager: Aaron Tanna Senior
Editor: Hayden Edwards Content Development Editor: Rashi Dubey Technical Editor: Saurabh
Kadave Copy Editor: Safis Editing Project Coordinator: Rashika Ba Proofreader: Safis Editing
Indexer: Pratik Shirodkar Production Designer: Vijay Kamble Marketing Coordinator: Anamika
Singh First published: January 2022
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80181-237-5
www.packt.com
For those who love coding.
– Daishi Kato
Contributors
About the author
Daishi Kato is a software engineer who is passionate about open source software. He has been a
researcher of peer-to-peer networks and web technologies for decades. His interest is in engineering,
and he has been working with start-ups for the last 5 years. He has been actively involved in open
source software since the 90s, and his latest work focuses on developing various libraries with
JavaScript and React.
I want to thank the people who have been close to me and supported me, especially my family,
my co-workers, and contributors to my open source projects.
He founded Darksun Tech and has contributed dozens of articles and book reviews to PCWorld India.
He co-authored the book Algorithm Analysis and Design, which is used as a textbook by the
Westwood Colleges (US) course on computer games programming.
Earlier in his career, Nalin was the lead architect of India's first 3D open-terrain game engine, and
part of the team that developed Rightserve, Asia's first targeted banner advertising service. He also
steered one of India's first cloud tutoring start-ups as its interim CTO.
Table of Contents
Preface
Part 1: React Hooks and Micro State Management
Chapter 1: What Is Micro State Management with React Hooks?
Technical requirements
Understanding micro state management
Working with hooks
Suspense for Data Fetching and Concurrent Rendering
Exploring global states
Working with useState
Updating the state value with a value
Updating the state value with a function
Lazy initialization
Using useReducer
Typical usage
Bailout
Primitive value
Lazy initialization (init)
Exploring the similarities and differences between useState and
useReducer
Implementing useState with useReducer
Implementing useReducer with useState
Using the init function
Using inline reducers
Summary
Part 2: Basic Approaches to the Global State
Chapter 2: Using Local and Global States
Technical requirements
Understanding when to use local states
Functions and arguments
React components and props
Understanding useState for local states
Limitation of local states
Effectively using local states
Lifting state up
Lift content up
Using global states
What is a global state?
When to use global states
Summary
Chapter 3: Sharing Component State with Context
Technical requirements
Exploring useState and useContext
Using useState without useContext
Using useContext with a static value
Using useState with useContext
Understanding Context
How Context propagation works
Limitations when using Context for objects
Creating a Context for a global state
Creating small state pieces
Creating one state with useReducer and propagating with
multiple Contexts
Best practices for using Context
Creating custom hooks and provider components
Factory pattern with a custom hook
Avoiding provider nesting with reduceRight
Summary
Chapter 4: Sharing Module State with Subscription
Technical requirements
Exploring the module state
Using a module state as a global state in React
Adding a basic Subscription
Working with a selector and useSubscription
Summary
Chapter 5: Sharing Component State with Context and
Subscription
Technical requirements
Exploring the limitations of module state
Understanding when to use Context
Implementing the Context and Subscription pattern
Summary
Part 3: Library Implementations and Their Uses
Chapter 6: Introducing Global State Libraries
Technical requirements
Working with global state management issues
Using the data-centric and component-centric approaches
Understanding the data-centric approach
Understanding the component-centric approach
Exploring the exceptions of both approaches
Optimizing re-renders
Using a selector function
Detecting property access
Using atoms
Summary
Chapter 7: Use Case Scenario 1 – Zustand
Technical requirements
Understanding module state and immutable state
Using React hooks to optimize re-renders
Working with read state and update state
Handling structured data
Pros and cons of this approach and library
Summary
Chapter 8: Use Case Scenario 2 – Jotai
Technical requirements
Understanding Jotai
Syntax simplicity
Dynamic atom creation
Exploring render optimization
Understanding how Jotai works to store atom values
Adding an array structure
Using the different features of Jotai
Defining the write function of atoms
Using action atoms
Understanding the onMount option of atoms
Introducing the jotai/utils bundle
Understanding library usage
Introduction to more advanced features
Summary
Chapter 9: Use Case Scenario 3 – Valtio
Technical requirements
Exploring Valtio, another module state library
Utilizing proxies to detect mutations and create an immutable
state
Using proxies to optimize re-renders
Creating small application code
The pros and cons of this approach
Summary
Chapter 10: Use Case Scenario 4 – React Tracked
Technical requirements
Understanding React Tracked
Using React Tracked with useState and useReducer
Using React Tracked with useState
Using React Tracked with useReducer
Using React Tracked with React Redux
Future prospects
Summary
Chapter 11: Similarities and Differences between Three
Global State Libraries
Technical requirements
Differences between Zustand and Redux
Example with Redux and Zustand
Comparing examples of Redux and Zustand
Understanding when to use Jotai and Recoil
Example with Recoil and Jotai
Comparing examples of Recoil and Jotai
Using Valtio and MobX
Example involving MobX and Valtio
Comparing examples of MobX and Valtio
Comparing Zustand, Jotai, and Valtio
Summary
BOSTON
AND
NEW YORK
Transcriber’s Notes:
Missing or obscured punctuation was silently
corrected.
Typographical errors were silently corrected.
Inconsistent spelling and hyphenation were
made consistent only when a predominant
form was found in this book.
*** END OF THE PROJECT GUTENBERG EBOOK DOODLES, THE
SUNSHINE BOY ***
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
ebookbell.com