Redux is a predictable state container for JavaScript apps. Andrew Clark, co-creator of Redux, is hosting this AMA to answer any questions you might have. Andrew recently joined Facebook as a front-end engineer. It's a great opportunity for everyone to get in touch with Andrew and have his insights on Redux and various other topics.
Ask Redux about:
Hosted by:
Hi folks !
I'm building my first App with React+Redux and I fear I'm doing an anti-pattern. I use a middleware to perform my network requests (something like this https://github.com/agraboso/redux-api-middleware). So whenever I need to perform a request, I have to dispatch an action. Thus, I feel like my actions become just like regular functions, I may dispatch them even if I don't really need to update the state. Does this look like an anti-pattern, or does dispatching actions for basically any tasks make sense ?
Thanks ! :)
In your opinion, what's the best way to get started with real world app development in React/Redux?
Hi Andrew and Dan :)
First, thanks for your awesome works !
What's the coolest thing you've made with redux ?
Redux is great and has given a new vocabulary for talking about things that is very functional and great. But middleware is an anomaly.
The idea that you can dispatch an action that will asynchronously dispatch other actions is very simple - but it muddles the idea of what an action is. It also confounds the search for what interleaving semantics are applied - for example - after I dispatch actions A and B, the store may recieve [B A' A'']
I find that it's best if Actions are thought of as items that are sequentially reduced into the store, and if a higher level streams library such as RxJS is in charge of interleaving streams with whatever semantics the application needs.
reactivex.io/documentation/operators/images/flatM…
I think Redux is great in its core focus, but RxJS is great at controlling the behavior of an aggregation of streams, and is more flexible than middleware, so I recommend keeping asynchrony out of actions.
But I'm glad so many people have found their own particular ways of using it. And I love how it pushes the few modules of my system that are not pure functions out to the periphery.
What are some of the most unique and interesting redux middleware you've seen?
Hey Andrew and Dan!
I was wondering what the relationship between ImmutableJS and React/Flux is like at facebook since they are both developed in house. I feel like ImmutableJS is a little overused sometimes but I was wondering to get some insight into how it is used at facebook and when you think it is appropriate for a Flux or Redux app
Thanks!
In terms of Routing, what do you recommend? Many developers while getting started with React/Redux tend to use react-router. What routing solution do you use in your own projects?
Hi Dan, I started learning ReactJS and now feel comfortable with the library. I know meteor fundamentals too. But I am facing a wall trying to create event based transitions from one component to another in SPA. Is redux the answer ? I know nothing about it yet. If yes, what are the best resources to learn?
When did you start realising that Redux was gaining popularity, and being used in production level apps? What were your feelings? What would be your advice for an open source aspirant?
Hey Dan,
Fancy to see you here. Here's a question apart from Redux. What is your work like in the React core team?
Are you excited by the advancements in GraphQL, Relay. Do you think Relay would replace Redux in the future, or would it still hold its ground? What are your thoughts?
Is it okay to have component wise state when using Redux as a store management? Have you guys come across any cases when there is a need for this?
Hi Dan, you often say that the Redux is inspired by a few core ideas in Elm; could you give a brief on what parts of Redux were inspired by Elm?
Thanks for the detailed answer to my last question! Do you think complex apps can be built without a state management solution like Redux?
Hi Andrew!
I have two fundamental questions:
[1] What is your favourite approach for managing routing - do you recommend coupling routing with the layout similar to ember router or react-router or would you recommend for a minimal router that just intercepts history change and updates the state tree and lets the components handle the rest of the logic.
The context is a portal like application having routes in the order of a hundred.
[2] Do you have any high level recommendations for structuring the state tree ? While it is understandable that it should be as normalized as possible, I am more concerned about information that denotes the current state of the application. Does it make sense to have a subtree that identifies what is currently relevant to the application ?
I used Redux a bit about a year ago and haven't looked at it again until very recently. I'm wondering if there are any Redux specific tools/middleware in the ecosystem that you see others commonly using together? Any that you don't mind endorsing?
I remember using reselect, redux-logger, and redux-thunk..
Hi Andrew, You've got hired by Facebook just recently, Congratz! What are your responsibilities and how is Redux affected if its affected at all.
The first time I saw Redux I thought it's a Elm clone in JavaScript. But the more I read about it, the more I found it derived. What are the differences in design solutions between Redux and Elm?
Hello Andrew.
How would you recommend to learn Redux for someone who has small amount of experience in Functional Programming?
I comfortable with React and now I want to use Redux with it, because approach I currently apply uses events to notify React components when my models have changed, kinda like Pub/Sub bus. What I've noticed this approach doesn't scale very well and it's hard to reason about code when code base becomes bigger. I've read few articles about Redux and I think it can help me.
I have a lot of experience with OOP code. I worked with Ruby/Rails and focused a lot on good object oriented design.
I don't have a lot of experience with functional programming in general. I have some experience with Scheme, mostly for learning recursion.
I kinda understand lambda calculus and ideas behind it, I even wrote Applicative Y-Combinator using things like Tennent's Correspondence Principle and so on.
Also I have some experience with Haskell. I know what "Currying" and "Partially applied function" concepts mean and what they for.
For me it looks like that Redux is heavily based on ideas from Functional Programming.
I think my question consists from 2 parts:
What learning path would you recommend in order to be comfortable with ideas on which Redux based on?
What knowledge/skills should I have in order to be really comfortable working with Redux and build applications using it?
I know I wrote a lot here, but I think it will help you give me more specific advice using provided information.
If you thinking that there is some programming language where some particular ideas expressed better, feel free to mention it. I've found that sometimes it's very beneficial to get to roots of some idea (yes, I do have a lot of free time). For example learning Smalltalk made me a better Ruby developer and OO developer in general.
Thank you a lot for any suggestion/advice :-)
Hi Andrew.
I'm going to start using Redux with React and in the process I want to understand how React/Redux and ideas from functional programming fit together.
Would it be better to work with Elm first and then after I've understand big picture shifted back to React/Redux?
Have you got around to playing with state management JS libraries other than Redux? How would you say they fare against Redux, or better what are a couple of things that a state management library other than Redux does better than Redux; and what are a couple of things that Redux does better than the counterparts?
Dan Abramov
Teams at Facebook can use whatever tech they want to use. Some internal projects use Redux. I think some parts of Facebook.com website also started to use it but those are subject to change because sometimes people want to customize it for their needs, or might replace that version of the product code with something else altogether. Don't forget Redux is super tiny so adding or removing it is not a huge deal.
Andrew Clark
Front-end engineer at Facebook
Front-end engineer at Facebook
ahmed-abdelkarim
front-end developer
Hi i was asking if it is a vaild pattren write a reusable reducer this way
`` const INC ='INC'
const counterReducer = (id, initialState) => (state = initialState, action) => {
if (action && action.meta.id === id) { switch (action.type) { case INC: return state+1 default: return state; } } else { return state; } };
const store = createStore(combineReducers({ c1:counterReducer("c1",0), c2:counterReducer("c2",1), c3:counterReducer("c3",2) }));
// dispatch action to first reducer// store.dispatch({type:INC,meta:{id:"c1"}});
// dispatch action to second reducer// store.dispatch({type:INC,meta:{id:"c2"}});
// dispatch action to second reducer//` store.dispatch({type:INC,meta:{id:"c3"}}); ```