IronTony / react-native-redux-toolkit-starter-app

📱🚀A POWERFUL React Native starter kit to bootstrap the start of your mobile app development
Mozilla Public License 2.0
373 stars 60 forks source link

Switch Redux setup to use Redux Toolkit #23

Closed markerikson closed 4 years ago

markerikson commented 4 years ago

Hi, I'm a Redux maintainer. I'd strongly recommend switching the Redux setup and logic in this project to use our new official Redux Toolkit package. It includes utilities to simplify several common Redux use cases, including store setup, defining reducers, immutable update logic, and even creating entire "slices" of state at once:

https://redux-toolkit.js.org

edit

Actually, now that I look further, it seems that the utils/redux.ts file has copy-pasted some of the types and functions from Redux Toolkit. Why not just use Redux Toolkit directly? Also, why not use the createSlice() function from RTK instead of createReducer + createAction ?

panz3r commented 4 years ago

Hi @markerikson ,

Thanks for your feedback, we really appreciate it and didn't expected it 😊 .

When we integrated redux into this starter app we considered using RTK but after some discussion we found that it wouldn't fit correctly into our basic idea.

The main reasons that brought us to this decision are the following:

So we started out that way and later found out how to integrate some part of RTK, we love the idea and cleanness of using createAction and createReducer (and also implemented something similar to handle redux-saga related methods), but still found unnecessary to add a whole dependency to just use half of it.

markerikson commented 4 years ago

FWIW, we do specifically recommend "feature folders" or "ducks", and createSlice makes it really easy to write ducks.

Also, adding sagas to an RTK setup can be done with:

configureStore({
    reducer,
    middleware: [...getDefaultMiddleware(), sagaMiddleware]
})

Not a lot of additional setup work there.

IronTony commented 4 years ago

Hi @markerikson ,

thank you for the opened issue, and also for the hints. Very appreciated 😍 Based on your hint, we will import Redux-toolkit and we will modify our store.ts file and the related others.

About the folders and files structure inside the redux folder, we prefer to have all files (actions/reducers/sagas/selectors) splitted to avoid long files with all code from different types in a single file just for a matter of readability.