You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
note : make a entry point {reducers/index.js} to combine all {dataReducer.js}
Implementation
import { combineReducers } from 'redux'
import appData from './dataReducer'
const rootReducer = combineReducers({
appData
})
export default rootReducer
Redux promise Middleware
The middleware enables optimistic updates and dispatches pending, fulfilled and rejected actions. It can be combined with redux-thunk to chain async actions.see later usage
note : create a store where we will integrate our app to the redux hirearchy
Implementation
note :
1. import applyMiddleware from redux
2. import thunk from redux-thunk
3. call createStore, passing in applyMiddleware as the second argument.
create store : {configureStore.js}
import { createStore } from 'redux'
import app from './reducers'
export default function configureStore() {
let store = createStore(app)
return store
}
note : create main file{index.js} to add basic redux implementation, where we need to import Provide from react-redux, we need to integrate store with provider and add our application component in it.
Implementation
import React from 'react'
import {
AppRegistry
} from 'react-native'
import { Provider } from 'react-redux'
import configureStore from './configureStore'
import App from './app'
const store = configureStore()
const app = () => (
<Provider store={store}>
<App />
</Provider>
)
AppRegistry.registerComponent('applicationComponent', () => app)
Redux Saga
1. it uses a combination of async await and generators to make for a smooth and fun to use api.
2. To run our Saga, we'll have to connect it to the Redux Store using the redux-saga middleware.
note : to run saga as middleware with your app , ist create {saga.js}
import { FETCH_DATA } from './constants'
import getPeople from './api'
export function fetchData() {
return {
type: FETCH_DATA,
payload: getPeople()
}
}
{update dataReducer.js } with api params
note : Redux Promise Middleware is different in that it takes over your actions and appends _PENDING, _FULFILLED, or _REJECTED actions depending on the outcome of your promise.