-
-
Save sahilpaudel/3ee091d6dd1e922a40e4fcf71d15b73c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I am trying to configure React Native with Redux, Saga, and React Navigation. | |
/App.js | |
const store = configureStore(); | |
export default App = () => { | |
const dispatch = useDispatch(); | |
const nav = useSelector(state => state.navigation); | |
return ( | |
<Provider store={store}> | |
<RootAppNavigation navigation={addNavigationHelpers({ dispatch, state: nav })} /> | |
</Provider> | |
) | |
} | |
AppRegistry.registerComponent('Scrapbook', () => App); | |
/configureStore.js | |
const configureStore = () => { | |
const sagaMiddleware = createSagaMiddleware(); | |
const middlewares = [sagaMiddleware]; | |
middlewares.push(reduxLogger); | |
return { | |
...createStore(rootReducer, applyMiddleware(...middlewares)), | |
runSaga: sagaMiddleware.run(rootSaga) | |
} | |
} | |
export default configureStore; | |
/rootReducer.js | |
import { persistCombineReducers } from 'redux-persist'; | |
import { AsyncStorage } from 'react-native' | |
const rootPersistConfig = { | |
key: "primary", | |
storage: AsyncStorage | |
} | |
const rootReducer = persistCombineReducers(rootPersistConfig, { | |
show, | |
navigation | |
}) | |
export default rootReducer; | |
/navigationReducer.js | |
import AppNavigator from '../../Navigator'; | |
import { NavigationActions } from 'react-navigation' | |
const router = AppNavigator.router; | |
const initialAction = { type: NavigationActions.Init } | |
const initialState = router.getStateForAction(initialAction) | |
export default (state = initialState, action) => ( | |
router.getStateForAction(action, state) | |
); | |
/Navigator.js | |
import LoginScreen from './screens/LoginScreen'; | |
import Bottom from './screens/Bottom'; | |
import { createAppContainer } from 'react-navigation'; | |
import { createStackNavigator } from 'react-navigation-stack'; | |
const MyStackNavigator = createStackNavigator({ | |
Login: { | |
screen: LoginScreen | |
}, | |
Home: { | |
screen: Bottom | |
}, | |
}, { | |
defaultNavigationOptions: { | |
title: 'Scrabook', | |
initialRouteName: 'Home', | |
} | |
}); | |
export default RootAppNavigation = createAppContainer(MyStackNavigator); | |
/package.json | |
{ | |
"main": "node_modules/expo/AppEntry.js", | |
"scripts": { | |
"start": "expo start", | |
"android": "expo start --android", | |
"ios": "expo start --ios", | |
"web": "expo start --web", | |
"eject": "expo eject" | |
}, | |
"dependencies": { | |
"@react-native-community/google-signin": "^4.0.0", | |
"@react-native-community/masked-view": "0.1.6", | |
"axios": "^0.19.2", | |
"expo": "^37.0.0", | |
"expo-google-app-auth": "^8.1.0", | |
"expo-google-sign-in": "~8.1.0", | |
"expo-secure-store": "~8.1.0", | |
"native-base": "^2.13.12", | |
"react": "16.9.0", | |
"react-dom": "16.9.0", | |
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.0.tar.gz", | |
"react-native-config": "^1.0.0", | |
"react-native-floating-action": "^1.20.0", | |
"react-native-gesture-handler": "~1.6.0", | |
"react-native-google-signin": "^2.1.1", | |
"react-native-paper": "^3.7.0", | |
"react-native-reanimated": "~1.7.0", | |
"react-native-safe-area-context": "0.7.3", | |
"react-native-screens": "~2.2.0", | |
"react-native-web": "^0.11.7", | |
"react-navigation": "^4.3.9", | |
"react-navigation-material-bottom-tabs": "^2.2.10", | |
"react-navigation-stack": "^2.4.0", | |
"react-redux": "^7.2.0", | |
"redux": "^4.0.5", | |
"redux-logger": "^3.0.6", | |
"redux-persist": "^6.0.0", | |
"redux-saga": "^1.1.3" | |
}, | |
"devDependencies": { | |
"@babel/core": "^7.8.6", | |
"babel-preset-expo": "^8.1.0" | |
}, | |
"private": true | |
} | |
/showReducer.js | |
export default ({ state = initalState, action }) => { | |
const type = action.type | |
switch (type) { | |
case SHOW_CREATE_SCRAPBOOK_MODAL: | |
return { | |
...state, | |
isCreateScrapbookModal: true | |
} | |
case HIDE_CREATE_SCRAPBOOK_MODAL: | |
return { | |
...state, | |
isCreateScrapbookModal: false | |
} | |
case SHOW_CREATE_POST_MODAL: | |
return { | |
...state, | |
isCreateScrapbookModal: true | |
} | |
case HIDE_CREATE_POST_MODAL: | |
return { | |
...state, | |
isCreateScrapbookModal: false | |
} | |
default: | |
return state | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment