Live data from Hacker News

Django React/Redux Base Project

github.com

41–50 of 79 posts

Re: Django React/Redux Base Project

#41

Django + React is an awesome combination that I recommend taking a look at. This repo is a good starting point but you can probably get rid of half of the dependencies if you aren't working on a team of developers. I am currently using Django + React on a personal project and took a slightly different route, no pun intended. Rather than using react router, as I never really liked client side routing, I use Django vie…

Hi

I'm not much of a frontend guy as I concentrate on the backend, but my team is working on a new React UI and I'm thinking of something similar, possibly.

Hopefully you can detail your plan a little more.

The reason our old Angular front-end was complex was because it was firing off dozens of small rest calls to grab every bit of state - drop downs, business logic, props, etc. - every time the route changed. It was a large SPA.

I'm proposing to do something different - break up the SPA into 6 or 7 MVC pages and push as much of the state into the html / JS that is returned, then use React only to update dynamic pieces of the front-end without having to regenerate the whole page.

Is this what you're describing or am I mistaken?

Re: Django React/Redux Base Project

#42
post #36
post #19

Earlier quoted context omitted.

If your project is small enough you can scrape it and generate all pages. You need a server only in development but then you can host it statically (and for free, e.g. on github). Check out hasgluten.com for an example, code here (pretty old version of react though): https://github.com/hasgluten/hasgluten

That's useful, thanks. The case I was interested in is where you'd like to have Django server-side-render the first request based on url, and then have react handle the rest via react-router and apis ala django-rest-framework. As a backend dev who got by with jquery soup and 0 frontend build tools before (use django bundling tools), even starting to approach the React ecosystem is a little daunting.

I was where you were at a few years ago, and I really don't think these type of large SPAs are appropriate for the vast majority of business / crud sites (i.e. not Google Maps, Facebook, etc.)

I work in Java / Scala world, but have been pulled into more front-end / UI work the last few years. It seems a lot of (younger) developers use the backend only as a Restful bridge to the DB.

After seeing what is Node, Angular npm, bower, grunt, etc. and now React and friends, I'm pushing my team back to the server for all business logic and using the front-end only for dynamic forms, animations, etc.

The JS tooling is just not as good as static backend frameworks, nor are the libraries. Trying to debug dozens of async calls using Chrome Dev Tools takes 10x as long as doing it on the backend, even with multiple threads.

Re: Django React/Redux Base Project

#44
post #32

So for people who think they need Redux, first read "You Might Not Need Redux" [0] by Dan Abramov himself, creator of Redux. Then also I would recommend MobX [1] over Redux, it's easier to get started and in my opinion easier and better in general. [0] https://medium.com/@dan_abramov/you-might-not-need-redux-be4... [1] https://github.com/mobxjs/mobx

Correct me if I'm misunderstanding, but one thing that worries me about MobX is that it seems leakier than Redux. Something that I really, really care about is that a well-architected React application should hardly care what the data layer is. The bulk of the application is comprised of dumb/presenter components and only the handful of container components know anything about Redux. Things like this (from the docs)…

You can easily maintain the abstraction of dumb components if you wish to:

    const TodoView = ({title, isFinished, onClick}) => (
        
            {title}
        
      )

    const TodoViewContainer = observer({todo} => (
         todo.finished = !todo.finished}
        />
      ))
But how often are you changing your app's data layer? Is the tradeoff _always_ worth it?

Mobx allows you to be as pragmatic or dogmatic as you choose to be

Re: Django React/Redux Base Project

#46

So for people who think they need Redux, first read "You Might Not Need Redux" [0] by Dan Abramov himself, creator of Redux. Then also I would recommend MobX [1] over Redux, it's easier to get started and in my opinion easier and better in general. [0] https://medium.com/@dan_abramov/you-might-not-need-redux-be4... [1] https://github.com/mobxjs/mobx

I'm 3 months into my first React/Redux project and wouldn't adopt Redux again if I were starting over. Don't get me wrong, it's not horrible, but it's not great either.

Compared with the extreme elegance and simplicity of React itself, Redux is verbose, boilerplatery and the way it integrates with React never feels natural.

I've taken a look at Mobx and had that aha moment of "yes, this is what the solution should look like!" Of course there's a big caveat here: not having really used it I don't know what its problems are yet. I'm comparing the real world warts of Redux with the platonic ideal of Mobx, but still it's definitely what I would try if I were starting a React project now.

Re: Django React/Redux Base Project

#47

Earlier quoted context omitted.

I wouldn't mind taking a look. I prefer VanillaJS. I'm currently using .Net/Java/C++ (yeah...) and am wanting to get away from that and switch to Python full time. So, I have been looking at as much Python code as I can lately.

I haven't documented/posted the JS code anywhere yet, but I did post some of the python server code on the Django developer mailing list at: https://groups.google.com/forum/#!topic/django-developers/q-... The JS code is still being changed around. The key here to maintain state consistency between front-end and back-end is that I transfer state from client to server via "data-model" HTML attributes. These attributes…

Thanks. I'll go check that out when I get a break.

Re: Django React/Redux Base Project

#48

I feel like the best way to do this is to just use cornice or DRF then use js scaffolding that is completely unaware of your backend. No need to join them at the hip like this, except maybe for the token based auth?

Are you aware of any boilerplate repos or examples that take this approach? Seemingly every example I've seen assumes Node is the backend.

After thinking about it for a second this could be because I've been looking at universal/isomorphic projects but I'd imagine you should be able to do rendering in Node and still have a completely separate API project.

Re: Django React/Redux Base Project

#49
Why is this packing together a backend tec and a frontend tec? I assume the frontend is generated from django models and views code? Or does one have to maintain frontend code manually - no that would not make sense at all. However I can not see any hint about how the frontend code gets generated?

Re: Django React/Redux Base Project

#50
post #32

Earlier quoted context omitted.

Correct me if I'm misunderstanding, but one thing that worries me about MobX is that it seems leakier than Redux. Something that I really, really care about is that a well-architected React application should hardly care what the data layer is. The bulk of the application is comprised of dumb/presenter components and only the handful of container components know anything about Redux. Things like this (from the docs)…

You can easily maintain the abstraction of dumb components if you wish to: const TodoView = ({title, isFinished, onClick}) => ( {title} ) const TodoViewContainer = observer({todo} => ( todo.finished = !todo.finished} /> )) But how often are you changing your app's data layer? Is the tradeoff _always_ worth it? Mobx allows you to be as pragmatic or dogmatic as you choose to be

> But how often are you changing your app's data layer? Is the tradeoff _always_ worth it?

Yes, because in my mind that's the litmus test that your app is properly data-agnostic. And a key thing about Redux is it stays that way -- it's actually difficult to leak your data store to child components. Even if I adopt the above approach with MobX it'd be incredibly easy for some other developer to start passing around stores everywhere.

My gut feeling is that MobX would be great for a personal project but doesn't scale that well.

Post reply on HN