Reactjs and routes

Asked

Viewed 577 times

1

The Reactjs framework comes with the idea of web components.

Well, he doesn’t use MVC

but what about routes? in a menu? how would I access my components correctly?

1 answer

5


Within an MVC structure, React.js would be the "V" of architecture. In other words, it is only and only the vision.

If you access the official website, there is a fragment of explanation intended for this:

JUST THE UI

Lots of people use React as the V in MVC. Since React makes no assumptions about the Rest of your technology stack, it’s easy to Try it out on a small Feature in an existing project.

Free translation:

ONLY THE UI

Many people use React as the V of MVC. Since React has no responsibility for the rest of its technology environment, it’s easy to use it in a small mechanism of an existing project.

In other words, any kind of logic is outside the scope of React.

But then, how do you solve your problem? React is seamlessly integrated with a MVC platform/framework, such as Backbone.js. If you want a reference, see:

Update

Talking to @Rodrigo in the comments below, I realized that the weather slightly depreciated the link above, that just works, but it is by far the best reference - including, if you notice, that was not my bibliographic proposal, the idea is:

[...] If you want some reference, see: [...]

However, as my architecture is always based on Backbone, a while ago I created a post on my blog that explains how to inject controllers to handle the dialogue layer between models and components efficiently. If it is of interest, here is the link.

  • I disagree with the statement, I do not think that React is perfectly integrable with Backbone.

  • Sorry I ended up clicking and I can’t edit, but coming back.. I disagree with the statement, I don’t think React is perfectly integratable with Backbone. React and the backbone view have the same functions, I don’t think it’s practical to render a React Commander in a Backbone view by passing all events (click, keyup etc) as an attribute, not to mention the confusion of context, and state (state) of the component. I think that in the case of React, it is worth using Flux, the conventional MVC does not work very well with React.

  • @Rodrigo It took me a while to read it, but finally I did. When you use the presentation layer like React, you detach the "View" layer of Backbone. In other words, one mechanism replaces the other - not used in parallel -, which makes both of them perfectly integrable and there is no contextual conflict as you said.

  • I agree that it is possible and it is a way to use, but using a React component within a backbone view sounds strange to me, and not very reactive when talking about Flux. Now using the backbone Router to send a Flux action for a A or B component to be rendered is another story. In the example of the site he uses the React as a stateless element for these cases I think Polymer is more advised since it organizes the styles better (css).

  • Again, using a Backbone view to render an React component is ugly - I don’t. In my case, I get discouraged completely the presentation layer of Backbone and I leave only and only the one of React. But... I understood what you meant: it is related to the link I referenced in my reply. From this point of view, yes! You are right! However, at the time of my reply, I had not found any alternative to better referencing. Even, to add to the topic, I made an issue.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.