Why do we need Flux with React?

I don’t understand why we need Flux with React, since the reaction itself allows us to maintain the state of the application. Each component has an initial state, and the state can be changed using user actions or any other asynchronous JavaScript.

Why is React called as soon as the view library, when it allows us to determine the state of the application, and also update the view whenever the state changes. This is not what the presentation does ... what makes the full MVC right?

For example: here is a Todo build with React only, and here is a build of Todo apps with Flux and React.

If we can only build Todo with React, then why do we need Flux?

+5
source share
2 answers

You are not NEED Flux the same that you do not need MVC These are both architectures, and you can, of course, build something without using it.

Would you create a non-MVC application in 2016? Probably not, this does not mean that people have not done this in the past.

Flux - awesome! But since most technologies in the technology industry are not always the right decision, it all depends on the requirements of the project.

Probably the biggest selling point of Flux is that it tries to provide data flow in one direction, which means that you know exactly where the data comes from. An application with a data stream for a component can have its own property, a property passed through the component tree, a local state variable, the result of a state variable when calling the API.

With Flux: "where does the data come from?" Answer: from the stores. Redux takes this and uses only one store.

Flux has been criticized because you need a lot of template code, but again this is a matter of compromise.

In the end, always your challenge depends on the needs of your project.

+2
source

In theory, you do not need a stream. In small applications, you do not need the thread for sure. But what if your application consists of hundreds of components? And one of your components is the form. The user fills out this form, and you submit its contents to the server. And get a response from the server with the new data. And suppose that response data and form data are needed by other components.

  • Without a stream: You can transfer data to the root component and then distribute it to all components. But if you also need to distribute data from many other components? This makes your application very complex.

  • with a stream: you move your data to stores, and all components that are interested in this data can get from there. You better control your application and source data.

I prefer abbreviation (only one repository and one source of truth)

edit:

Why is React called as a view library, even if it can handle the state of the application?

MVC is an architectural example of software. He divides this software application into three interconnected parts (models, views, controllers). If we think about reaction and MVC, this will be consistent with the view. But this is nothing wrong. This does not mean that you can use it only for viewing. It allows you to create regular applications.

But on the other hand, you can use it as a representation for other frameworks (for example, you can use it with angular).

In other words, it is a very flexible library for many purposes.

+4
source

Source: https://habr.com/ru/post/1244840/


All Articles