更新时间:2021-07-02 18:48:13
cover
Title Page
Copyright
Learning Redux
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
About the book
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
Why Redux?
Defining the application state
Defining actions
Tying state and actions together
Redux' three fundamental principles
Single source of truth
The read-only state
State changes are processed with pure functions
Introduction to the Redux ecosystem
Summary
Implementing the Elements of Redux
The Redux cycle
An action is dispatched
The main reducer function gets executed
Redux saves the new state
Strictly unidirectional data flow
Running code examples
Setting up a new project
Setting up Node.js
Initializing the project
Setting up webpack
Setting up Babel
Setting up the entry files
Running webpack
Setting up Redux
The template code
Implementing actions and action creators
Separating action types
ES2015 - import/export
Introducing action creators
ES2015 - arrow functions
Code example
Implementing reducers
Defining/importing action types
Defining action creators
Writing the posts reducer
The main structure of a reducer
ES2015 - using destructuring and the rest operator to parse the action
Handling CREATE_POST – creating a new post
Handling EDIT_POST – editing posts
Testing out our reducer
Writing the filter reducer
Combining reducers
Testing out the full reducer
The store – combining actions and reducers
Creating the store
Subscribing to state changes
Dispatching actions
Rendering the user interface
Creating sample data
Handling the user input
Combining Redux with React
Why React?
The principles of React
Setting up React
Rendering simple text
Rendering with JSX
Setting up JSX
Using JSX
Example code
First steps with React
Creating a simple React element
Creating a static React component
Functional components
Using components
Class components – dynamic React components
Creating a static class component
Creating a dynamic class component
Setting the initial state
React life cycle methods
Updating the state