top of page

Redux with React-native

  • Writer: Jino Shaji
    Jino Shaji
  • Mar 11, 2018
  • 1 min read

Updated: Jun 13, 2020

Refer this link to view the source code of Redux with react native

Concepts:




Redux- Basics : React (Below source code is of React Not of  React-native)


const redux = require(‘redux’);
const createStore = redux.createStore;
const initialState = {
 counter: 0
}
// Reducer
const rootReducer = (state = initialState, action) => {
 if (action.type === ‘INC_COUNTER’) {
 return {
            …state,
 counter: state.counter + 1
        };
    }
 if (action.type === ‘ADD_COUNTER’) {
 return {
            …state,
 counter: state.counter + action.value
        };
    }
 return state;
};
// Store
const store = createStore(rootReducer);
console.log(store.getState());
// Subscription
store.subscribe(() => {
 console.log(‘[Subscription]’, store.getState());
});
// Dispatching Action
store.dispatch({type: ‘INC_COUNTER’});
store.dispatch({type: ‘ADD_COUNTER’, value: 10});
console.log(store.getState());

Recent Posts

See All
Redux-Thunk Small Overview

Introduction Redux Thunk middleware allows you to write action creators that return a function instead of an action. The thunk can be...

 
 
 

Comments


bottom of page