How can I access a portion of the state in a reducer
up vote
1
down vote
favorite
In my case I have a reducer that is a filter configuration and instead of initializing it with an object
initial_state = {ditance: 2, showMan: false ...}
I want those values to take them from the store because the user has logged in and those values are already in the bbdd of firebase firestore,
I am using the library react-redux-firestore and that information is already in another reducer. The problem is that if I use the static initial_state when I kill the application it is no longer synchronized with what is in the database.
So what I ask is that if there is any way to be able to take in a reduce the portion of a state that there is in another reduce to generate the new state. I've seen that you can send an action or something like that but I'm looking for another way to do it, if possible .
reactjs redux state reducers
add a comment |
up vote
1
down vote
favorite
In my case I have a reducer that is a filter configuration and instead of initializing it with an object
initial_state = {ditance: 2, showMan: false ...}
I want those values to take them from the store because the user has logged in and those values are already in the bbdd of firebase firestore,
I am using the library react-redux-firestore and that information is already in another reducer. The problem is that if I use the static initial_state when I kill the application it is no longer synchronized with what is in the database.
So what I ask is that if there is any way to be able to take in a reduce the portion of a state that there is in another reduce to generate the new state. I've seen that you can send an action or something like that but I'm looking for another way to do it, if possible .
reactjs redux state reducers
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
In my case I have a reducer that is a filter configuration and instead of initializing it with an object
initial_state = {ditance: 2, showMan: false ...}
I want those values to take them from the store because the user has logged in and those values are already in the bbdd of firebase firestore,
I am using the library react-redux-firestore and that information is already in another reducer. The problem is that if I use the static initial_state when I kill the application it is no longer synchronized with what is in the database.
So what I ask is that if there is any way to be able to take in a reduce the portion of a state that there is in another reduce to generate the new state. I've seen that you can send an action or something like that but I'm looking for another way to do it, if possible .
reactjs redux state reducers
In my case I have a reducer that is a filter configuration and instead of initializing it with an object
initial_state = {ditance: 2, showMan: false ...}
I want those values to take them from the store because the user has logged in and those values are already in the bbdd of firebase firestore,
I am using the library react-redux-firestore and that information is already in another reducer. The problem is that if I use the static initial_state when I kill the application it is no longer synchronized with what is in the database.
So what I ask is that if there is any way to be able to take in a reduce the portion of a state that there is in another reduce to generate the new state. I've seen that you can send an action or something like that but I'm looking for another way to do it, if possible .
reactjs redux state reducers
reactjs redux state reducers
edited Nov 8 at 21:34
Rajab Shakirov
1,13241735
1,13241735
asked Nov 8 at 11:09
jorge morales lopez
62
62
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
if data is in another reducer, you can get the value and pass it with action when you call it.
but if it's in the same reducer, you pass two parameters essentially
const reducer = (state = initial_state, action) = > {
switch (action.type){
case actionType.TOGGLE_SHOWMAN:
return { ...state, showMan: ! state.showMan };
default:
return state;
}
}
so you can access previous state by calling state inside the reducer
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
if data is in another reducer, you can get the value and pass it with action when you call it.
but if it's in the same reducer, you pass two parameters essentially
const reducer = (state = initial_state, action) = > {
switch (action.type){
case actionType.TOGGLE_SHOWMAN:
return { ...state, showMan: ! state.showMan };
default:
return state;
}
}
so you can access previous state by calling state inside the reducer
add a comment |
up vote
0
down vote
if data is in another reducer, you can get the value and pass it with action when you call it.
but if it's in the same reducer, you pass two parameters essentially
const reducer = (state = initial_state, action) = > {
switch (action.type){
case actionType.TOGGLE_SHOWMAN:
return { ...state, showMan: ! state.showMan };
default:
return state;
}
}
so you can access previous state by calling state inside the reducer
add a comment |
up vote
0
down vote
up vote
0
down vote
if data is in another reducer, you can get the value and pass it with action when you call it.
but if it's in the same reducer, you pass two parameters essentially
const reducer = (state = initial_state, action) = > {
switch (action.type){
case actionType.TOGGLE_SHOWMAN:
return { ...state, showMan: ! state.showMan };
default:
return state;
}
}
so you can access previous state by calling state inside the reducer
if data is in another reducer, you can get the value and pass it with action when you call it.
but if it's in the same reducer, you pass two parameters essentially
const reducer = (state = initial_state, action) = > {
switch (action.type){
case actionType.TOGGLE_SHOWMAN:
return { ...state, showMan: ! state.showMan };
default:
return state;
}
}
so you can access previous state by calling state inside the reducer
answered Nov 9 at 9:39
Biskrem Muhammad
51811015
51811015
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206542%2fhow-can-i-access-a-portion-of-the-state-in-a-reducer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown