Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

Nesting/combining combined reducers in redux?

$
0
0

How to combine combined reducers for example like this?:

export const streamsRootReducer = combineReducers({
    streamsPending: streamsPendingReducer,
    streams: streamsReducer,
    streamsError: streamsErrorReducer,
    streamsPageOffset: streamsPageOffsetReducer,
    streamsRefresh: streamsRefreshReducer
}); 

export const newsRootReducer = combineReducers({
    newsPending: newsPendingReducer,
    news: newsReducer,
    newsError: newsErrorReducer,
    newsRefresh: newsRefreshReducer
})

export const rootReducer = combineReducers({
    streamsRootReducer: streamsRootReducer,
    newsRootReducer: newsRootReducer
})

export type StreamsRootState = ReturnType<typeof streamsRootReducer>;
export type NewsRootState = ReturnType<typeof newsRootReducer>;

and in the Store like this:

import { rootReducer } from '../reducers/index';


const sagaMiddleware = createSagaMiddleware();
const middlewares = [sagaMiddleware, reduxLogger];

const configureStore = () => {
    const store = createStore(
        rootReducer,
        compose(applyMiddleware(...middlewares))
    );
    sagaMiddleware.run(rootSaga);
    return store;
}

export default configureStore;

and in my screens i want to do like this:

...
const mapStateToProps = (state: NewsRootState) => ({
    newsPending: state.newsPending,
    news: state.news,
    newsError: state.newsError,
    newsRefresh: state.newsRefresh
})

export default connect(
    mapStateToProps,
    { fetchNewsPending, fetchNewsRefresh }
)(NewsScreen)

i am getting errors if i am trying to combine already combined reducers but nesting all my reducers in one combined looks like a mess becasue i want to do similar to this 2 combined in the end of my project i will maybe have like 15 - 20 reducers, should i put all of the in to one rootReducer or can i nest them somehow like in my example? Is there exist better solution to do something like i wanted ?


Viewing all articles
Browse latest Browse all 6211

Trending Articles