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
import React from 'react'; | |
import {View, Text, TouchableOpacity} from 'react-native'; | |
import {useDispatch} from 'react-redux'; | |
import {setIsLoggedIn} from '../../redux/actions/UserActions'; | |
const Login = () => { | |
const dispatch = useDispatch(); | |
const onLogin = () => { | |
dispatch(setIsLoggedIn(true)); | |
}; |
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
import React from 'react'; | |
import {Provider} from 'react-redux'; | |
import store, {persistor} from './src/redux/store'; | |
import AppWrapper from './src/components/AppWrapper'; | |
import {PersistGate} from 'redux-persist/integration/react'; | |
const App = () => { | |
return ( | |
<Provider store={store}> | |
<PersistGate loading={null} persistor={persistor}> |
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
import React from 'react'; | |
import {useSelector} from 'react-redux'; | |
import {selectIsLoggedIn} from '../../redux/selectors/UserSelector'; | |
import Counter from '../../screens/counter'; | |
import Login from '../../screens/login'; | |
const AppWrapper = () => { | |
const isLoggedIn = useSelector(selectIsLoggedIn); | |
return !!isLoggedIn ? <Counter /> : <Login />; | |
}; |
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
import { createSelector } from 'reselect'; | |
export const selectCounterValue = createSelector( | |
(state) => state.counter, | |
(counter) => counter.value, | |
); |
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
import { createSelector } from 'reselect'; | |
export const selectIsLoggedIn = createSelector( | |
(state) => state.user, | |
(user) => user.isLoggedIn, | |
); |
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
import {configureStore} from '@reduxjs/toolkit'; | |
import logger from 'redux-logger'; | |
import { | |
persistStore, | |
persistReducer, | |
FLUSH, | |
REHYDRATE, | |
PAUSE, | |
PERSIST, | |
PURGE, |
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
import { combineReducers } from 'redux'; | |
import CounterReducer from './CounterReducer'; | |
import UserReducer from './UserReducer'; | |
const Reducers = combineReducers({ | |
user: UserReducer, | |
counter: CounterReducer | |
}); | |
export default Reducers; |
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
import {createReducer} from '@reduxjs/toolkit'; | |
import {PURGE} from 'redux-persist'; | |
import {CounterActionTypes} from '../actions/CounterActions'; | |
const initialState = {value: 0}; | |
const CounterReducer = createReducer(initialState, builder => { | |
builder | |
.addCase(CounterActionTypes.INCREMENT, state => { | |
state.value++; |
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
import { createAction } from '@reduxjs/toolkit'; | |
export const CounterActionTypes = { | |
INCREMENT: 'INCREMENT', | |
DECREMENT: 'DECREMENT', | |
}; | |
export const incrementCount = createAction(CounterActionTypes.INCREMENT); | |
export const decrementCount = createAction(CounterActionTypes.DECREMENT); |
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
import {createAction} from '@reduxjs/toolkit'; | |
// createAction function is used to define a redux action, | |
// it takes an action type and returns an action creator for that type. | |
// The action creator can be called either without arguments or with a payload to be attached to the action. | |
export const UserActionTypes = { | |
SET_IS_LOGGED_IN: 'SET_IS_LOGGED_IN', | |
}; | |
export const setIsLoggedIn = createAction(UserActionTypes.SET_IS_LOGGED_IN); |