React Native Redux

import { createStore, applyMiddleware, compose } from 'redux';
import ReduxThunk from 'redux-thunk';
import rootReducer from './reducers/reducers';
import ResumeReducer from './reducers/resumeReducer';
import EducationReducer from './reducers/educationReducer';
import ExperianceReducer from './reducers/experianceReducer';
import ProjectReducer from './reducers/projectReducer';
import ResumeOrderReducer from './reducers/resumeOrderReducer';

import { combineReducers } from 'redux';

var allReducers=combineReducers({
    resume:ResumeReducer,
    token: rootReducer,
    education:EducationReducer,
    experiance:ExperianceReducer,
    project:ProjectReducer,
    order:ResumeOrderReducer
});

const middlewares = [ReduxThunk];

const store = createStore(
     allReducers,
    {},// default state of the application
    compose(applyMiddleware(...middlewares)),
);

export default store;
npm install redux
npm install react-redux
npm install redux-thunk
--save

// In index.js

import {Provider} from 'react-redux';
import {combineReducer} from 'react-redux';
import store from './src/Redux/store';

const Root = () => (
    <Provider store={store}>
        <App />
    </Provider> 
    
)
import { combineReducers } from 'redux';
import { GET_EDUCATION,SET_EDUCATION, LOADING, ERROR} from '../actions/actionTypes';

const educationReducer = (state = {
    education:{},
    loading: false,
    error: null,
}, action) => {
    switch (action.type) {
        case GET_EDUCATION:
            return { ...state,education:action.data };
        case SET_EDUCATION:
            return { ...state, education: action.data ,loading:false};
        case LOADING:
            return { ...state, loading: true };
        case ERROR:
            return { ...state, error: action.data };
        default:
            return state;
    }
};

export default educationReducer;
// export default combineReducers({
//     token: rootReducer
// });
export const GET_TOKEN = 'GET_TOKEN';
export const SET_TOKEN = 'SET_TOKEN';
export const REMOVE_TOKEN = 'REMOVE_TOKEN';
export const LOADING = 'LOADING';
export const ERROR = 'ERROR';
export const POST_SIGNUP = 'POST_SIGNUP';

export const GET_HEADING ="GET_HEADING";
export const SET_HEADING ="SET_HEADING";


export const GET_EDUCATION="GET_EDUCATION"
export const SET_EDUCATION="SET_EDUCATION"

export const SET_EXPERIANCE="SET_EXPERIANCE"

export const SET_PROJECT="SET_PROJECT"


export const GET_RESUME_ORDER="GET_RESUME_ORDER";
export const SET_RESUME_ORDER="SET_RESUME_ORDER";
import { GET_EDUCATION,SET_EDUCATION} from './actionTypes';
import AsyncStorage from '@react-native-community/async-storage';
import server from '../../config/config'

export const getEducation = (data) => ({
    type: GET_EDUCATION,
    data:data,
});

export const setEducation = data => ({
    type: SET_EDUCATION,
    data:data
});


export const loading = bool => ({
    type:  LOADING,
    data: bool,
});

export const error = error => ({
    type: ERROR,
    data:error,
});


export const postEducation =(data)=>dispatch=>{
    console.log('---------post education ---------')
        fetch(server.backend+'resume/educationinfo/', {
            method: 'POST',
            headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
            token:data.token
        },
        body: JSON.stringify({
            school:data.school,
            grade:data.grade,
            title:data.title,
            from:data.from,
            to:data.to


        })
        }).then(res=>res.json())
        .then(response=>{
            console.log(response)
            // dispatch(getResumeEducation())
        }).catch(err=>{
            dispatch(error);
        });
}

export const getResumeEducation =(data)=>dispatch=>{
    console.log('---in get Resume --')
    console.log(data)
    fetch(server.backend+'resume/educationinfo',{
        method: 'GET',
        headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        token:data
        }
    })
    .then((response) => response.json())
    .then((json) => {
        console.log('---response')
        console.log(json.education)
        dispatch(setEducation(json.education));
        // dispatch(getHeading())

    })
    .catch((error) => {
      console.error(error);
    });
}
export const deleteEducationInfo =(data)=>dispatch=>{
    console.log('---in get delete education info --')
    console.log(data)
    fetch(server.backend+'resume/educationinfo/delete/'+data.id,{
        method: 'GET',
        headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        token:data.token
        }
    })
    .then((response) => response.json())
    .then((json) => {
        console.log('---response')
        // console.log(json.education)

        // dispatch(setEducation(json.education));
        // dispatch(getHeading())

    })
    .catch((error) => {
      console.error(error);
    });
}

Similiar Collections