Documentation: Redux Chinese Documentation The official Redux documentation defines Redux as: a predictable JavaScript application state management container. 1. The relationship between redux and reactRedux does not only provide state management for react applications, it also supports other frameworks. React is an abstraction layer for DOM (UI library), not a complete solution for web applications. Therefore, react is more complicated when it comes to data processing and communication between components. For large and complex applications, these two aspects are precisely the most critical. Therefore, it is difficult to write large applications using only React. Advantages of redux: Centrally store and manage application status When dealing with component communication issues, ignore the hierarchical relationship between components Simplify communication between components in large and complex applications The data flow is clear and it is easy to locate bugs 2. React multi-component sharingExtract the states of all components and construct a centralized state tree by analogy with the React component tree. This state tree corresponds one-to-one with the React component tree, which is equivalent to stateful modeling of the React component tree: ├── src ├── store # redux directory, generally called store │ ├── index.js # Define and export the store. The reducer will be imported │ └── reducer # reducer function ├── App.js # root component, import Father and Uncle components 1. Redux can ignore the component hierarchy 2. For the component system, redux is a third-party, global "variable" 3. Three core concepts of redux Core concepts: 1. storeStore is a warehouse, the core of Redux, integrating action and reducer, similar to the store of vuex Features:
import { createStore } from 'redux' // Create a store const store = createStore(reducer) 2. action Features:
const action1 = { type:'addN', payload: 12 } //store.dispatch(action1) const action2 = { type:'add', payload: 1 } 3. Reducer (pure function)effect: 1. Initialization state 2. Modify status Modify state: return a new state based on the old state and action passed in initState = 0 function reducer(state = initState, action) { return state } SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: The difference between mysql outer join and inner join query
>>: Content-type description, that is, the type of HTTP request header
Table of contents Examples from real life Slow qu...
Preface The apt-get command is a package manageme...
Preface In the previous article Detailed Explanat...
Use HTML to create complex tables. Complex tables...
Table of contents 1.1. Network access between con...
Table of contents 1. Auxiliary functions 2. Examp...
The solution to the problem that the PHP7.3 versi...
This article example shares the specific code for...
MySQL version 5.0 began to support stored procedu...
1. What is responsive design? Responsive design i...
Solution to MySql service disappearance for unkno...
This article example shares the specific code of ...
Table of contents No slots Vue2.x Slots With slot...
Table of contents 1. Self-enumerable properties 2...
The virtual machine used is CentOS 8.4, which sim...