Does redux have to be paired with react?
Redux does not have to be paired with react. In addition to supporting React, it also supports other UI frameworks; and redux is not suitable for all projects and all applications; in react, if you can do without redux, don’t use redux.
Recommendation: "react video tutorial"
redux is a JavaScript state container that mainly provides state management. Can run on server, client, and native applications. In addition to supporting React, it also supports other UI frameworks and is small in size, only 2kb. When using it with React, you can use the react-redux plug-in to further enhance our development experience.
Before starting today’s topic, there are a few points I need to emphasize
The state of react and the state of redux are two completely unrelated things. Remember not to mix things up. The state of react is an attribute that exists in a class component to store its own variables, and the state of redux is the state of a certain namespace in the store of the entire application. The two have nothing to do with each other.
Redux is independent of react. You can choose to use it or not. If you are not using redux-based scaffolding, you need to reference it separately if you want to use redux. There is no redux in the react package.
If you want to use redux in your application, you need to associate react with redux. There is a package called react-redux, which is used to associate react with redux. There is a high-order function in it. It's called connect, and it accepts two methods, mapStateToProps and mapDispatchToProps. These two methods inject redux's state into react's props.
The above is a review of some basic knowledge points of redux. Next, we enter the topic.
Usage scenarios of redux
If your React application has a lot of states and is difficult to maintain, redux is a good choice at this time. (The state mentioned here is the state of react)
If you need data sharing, that is, multiple react components need to use the same data source.
If you need some global status control, such as the current logged-in person in the application, we may use the logged-in person information in which component. If we register it in global redux, then we will There is no need to worry about which component is used. When we use it, we can just take it directly from the global redux.
The business logic of a certain component is too complex. It is too cumbersome to process these data in the react component. We can consider part of the logic Split into redux.
Using redux can separate data and UI. If you want to achieve such an effect, you can try to use redux.
Why should we reduce the use of redux
Students who have read Brother Ruan Yifeng’s blog must have seen these sentences
If you don’t know whether you need Redux, then you don’t need it.
You only need Redux if you encounter problems that React can't solve.
So redux is not suitable for all projects and applications.
Using redux requires creating a lot of template code, which will make state updates very complicated. Anyone who uses it knows this, haha.
Using too much redux will make the application lose flexibility
Redux brings functional programming, immutability ideas, etc. In order to cooperate with these concepts, developers must write many "patterns" Code (boilerplate)" is cumbersome and repetitive that developers are not willing to tolerate. Of course, there are many hacks aimed at reducing boilerplate, but at this stage, it can be said that Redux is inherently cumbersome;
If you use Redux, your application must use objects or arrays to describe the state; OMG !
Use Redux, then your application must use plain objects, that is, actions, to describe changes; OMG!
Use Redux, then your application must use pure functions to handle changes; OMG!
In applications, many states must be abstracted to the store, so when should we use local states and when should we access the Redux store? You can't just write business happily. A change requires writing action (action creator), reducer, etc.;
Compared with Mobx, which combines responsiveness with functional style, the programming experience is "discounted"
The above is a quote from a netizen. It can be seen that there are many disadvantages when using redux too much. I will not list its disadvantages one by one here. Interested students can search for it themselves. In general, I think that redux can be used without redux
After reading this, I want to solve the questions in the minds of some readers: "When should we use react's state?" Use redux state?" The answer is clear.
After all, redux is a relatively successful framework. The data flow in it is also very classic and solves many problems. Everything has pros and cons. As long as we make good trade-offs, I believe we can write better applications. .
The above is the detailed content of Does redux have to be paired with react?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to build a real-time chat application using React and WebSocket Introduction: With the rapid development of the Internet, real-time communication has attracted more and more attention. Live chat apps have become an integral part of modern social and work life. This article will introduce how to build a simple real-time chat application using React and WebSocket, and provide specific code examples. 1. Technical preparation Before starting to build a real-time chat application, we need to prepare the following technologies and tools: React: one for building

React front-end and back-end separation guide: How to achieve front-end and back-end decoupling and independent deployment, specific code examples are required In today's web development environment, front-end and back-end separation has become a trend. By separating front-end and back-end code, development work can be made more flexible, efficient, and facilitate team collaboration. This article will introduce how to use React to achieve front-end and back-end separation, thereby achieving the goals of decoupling and independent deployment. First, we need to understand what front-end and back-end separation is. In the traditional web development model, the front-end and back-end are coupled

How to use React and Flask to build simple and easy-to-use web applications Introduction: With the development of the Internet, the needs of web applications are becoming more and more diverse and complex. In order to meet user requirements for ease of use and performance, it is becoming increasingly important to use modern technology stacks to build network applications. React and Flask are two very popular frameworks for front-end and back-end development, and they work well together to build simple and easy-to-use web applications. This article will detail how to leverage React and Flask

How to build a reliable messaging application with React and RabbitMQ Introduction: Modern applications need to support reliable messaging to achieve features such as real-time updates and data synchronization. React is a popular JavaScript library for building user interfaces, while RabbitMQ is a reliable messaging middleware. This article will introduce how to combine React and RabbitMQ to build a reliable messaging application, and provide specific code examples. RabbitMQ overview:

React Responsive Design Guide: How to Achieve Adaptive Front-end Layout Effects With the popularity of mobile devices and the increasing user demand for multi-screen experiences, responsive design has become one of the important considerations in modern front-end development. React, as one of the most popular front-end frameworks at present, provides a wealth of tools and components to help developers achieve adaptive layout effects. This article will share some guidelines and tips on implementing responsive design using React, and provide specific code examples for reference. Fle using React

React code debugging guide: How to quickly locate and resolve front-end bugs Introduction: When developing React applications, you often encounter a variety of bugs that may crash the application or cause incorrect behavior. Therefore, mastering debugging skills is an essential ability for every React developer. This article will introduce some practical techniques for locating and solving front-end bugs, and provide specific code examples to help readers quickly locate and solve bugs in React applications. 1. Selection of debugging tools: In Re

ReactRouter User Guide: How to Implement Front-End Routing Control With the popularity of single-page applications, front-end routing has become an important part that cannot be ignored. As the most popular routing library in the React ecosystem, ReactRouter provides rich functions and easy-to-use APIs, making the implementation of front-end routing very simple and flexible. This article will introduce how to use ReactRouter and provide some specific code examples. To install ReactRouter first, we need

How to use React and Google BigQuery to build fast data analysis applications Introduction: In today's era of information explosion, data analysis has become an indispensable link in various industries. Among them, building fast and efficient data analysis applications has become the goal pursued by many companies and individuals. This article will introduce how to use React and Google BigQuery to build a fast data analysis application, and provide detailed code examples. 1. Overview React is a tool for building
