I am studying Redux combining it with Flutter, and I have this question, does making stateful widgets make sense in Flutter if you follow redux architecture? I could think that for animations and little widgets it's better to make a stateful widget rather than a new attribute to the real appState, but I am not really sure... I need someone to clarify me this dummy question.
Redux is not even close to replacing StatefulWidget.
A simple example is animations. Each of them requires to store, dispose and interact with an AnimationController/Tweens.
Redux really is for a serializable state. Typically what comes from your API, which you may or may not want to store on the device.
StatefulWidget kicks in for everything else.
Definitely. Use stateful widget for rather short-lived UI state and Redux for longer-living state and state managed by business logic.
Related
I need some functionality to be run after any/every action, but after the reducer has run and state has changed, so meta-reducers won't work here.
I found the answer in ActionsSubject. The second answer in this question was exactly what I needed - how to subscribe to action success callback using ngrx and effects.
I needed a way to watch what was happening in ngRx because the library I'm developing needs to be able to be used in any javascript environment. It might be React or Swift, or even wrapped in a NodeJs api. I'm happy ngRx provides an easy way to monitor the actions flowing through the system - that means Angular is on the "ok list" to use our library.
What's the company standard? If a company decides to adopt Redux, do I need to convert every state/prop into redux form?
For example. I have a loading/setLoading state for the home page. Can't see if being used in other places. Do I need to make a redux version of actions for it?
No, as stated in the Redux style guide (general reading recommendation!), you should Evaluate Where Each Piece of State Should Live.
Not everything needs (or even should) be global data. Only use Redux for stuff that is "global". It does not replace props or local component state!
Im fairly new to redux, my question is. Do i need to use middleWare if i am using Redux-thunk. I need to make an API call and i want to know what i need in order to make that call using redux. I know how to do it without redux, but now i am building my E-commerce site and i need to use redux, but i am not very familiar with using thunk to fetch data. There are plenty of tutorials out there but non of them really helped or they are outdated. If someone came across a video feel free to post the link. Thank you in advance!
Best course of action would be to go through the official redux essentials tutorial which teaches modern redux and also has a whole chapter on data fetching (but read it from the beginning!)
When I searched for Redux most of the time I get the answer
Redux is a predictable state container for JavaScript and comes as an
external library which can be used together with front-end frameworks
like React, Angular, Ember.js, Backbone, etc.
I did not get the definition actually. What does it mean by **predictable state container **?
And as a new tool, it should solve some problems with web development. So, what redux does and how it facilitates us?
I think when someone says that Redux is a predictable state container it means that redux has a very strict way how to change the data, sometimes called unidirectional data flow.
I mostly used it in React application, so I can tell which problem it solves in this case. While your application is small, you probably will not see the reason to use Redux, but when it grows, when you have lots of components which use the same data and have to communicate with each other, it becomes really painful to store all state somewhere in the root components and pass it through all the children. There may be performance issues as well, all components between a root one a chield which needs some part of your state will be re-rendered.
So using Redux easily connect your components and select those parts of the state which they need. Also, communication between components becomes much easier, instead of passing callbacks to props, your components just listed to state and represent it, any time you need to change a state just send an action.
Regarding predictable state management, Redux is some kind of event sourcing, instead of changing a state directly, so send actions (events) which describe how to modify the state and reducer applies these changes.
There are way more things to say about Redux, at least middlewares, if you are familiar with Rx, you can try to use redux-observable which are really powerful, you can listen to some actions or a state changes to combine it with others. I recommend you to take a look at redux documentation and some article like this, I believe you will find an answer to your question.
Assuming I want to reuse a component with redux, what are my options?
In more detail:
Let's assume I have a generic list component with items and filter input. I want to use this component in 2 places. The component needs to be closed API, meaning it should dispatch and reduce the actions all within itself. It needs to handle state changes and show the filtered items as well.
Let's assume the reducers are exposed publicly to build the store.
What would be the best approach of building the state object, the reducer and the action.
The main issue is how to 'bind' each component to a different items property on the store state.
Update:
Here is a discussion very similar to my qiestion:
Using Redux in reusable React component. I commented on the discussion with a proposal I found. If it will be accepted I will post it here. Meanwhile you can answer my question with your proposals.
I'm new to Redux, and haven't tried the library yet, but MrEfrem/redux-fly seems to me as a very interesting answer to this problem.