Skip to content

Instantly share code, notes, and snippets.

@divyanshu013
Created March 18, 2019 13:38
Show Gist options
  • Save divyanshu013/1e1fe06b147ebb3719466c8bdfad9a1f to your computer and use it in GitHub Desktop.
Save divyanshu013/1e1fe06b147ebb3719466c8bdfad9a1f to your computer and use it in GitHub Desktop.
React component and redux module template
import React from 'react';
import { View } from 'react-native';
const <%= name %> = () => (
<View>
</View>
);
export default <%= name %>;
const ACTIONS = {
LOAD_BEGIN: '<%= name %>/LOAD_BEGIN',
LOAD_END: '<%= name %>/LOAD_END',
LOAD_ERROR: '<%= name %>/LOAD_ERROR',
};
const load = () => ({ type: ACTIONS.LOAD_BEGIN });
const loadEnd = () => ({ type: ACTIONS.LOAD_END });
const loadError = () => ({ type: ACTIONS.LOAD_ERROR });
const INITIAL_STATE = {
loadError: false,
loading: true,
};
const reducer = (state = INITIAL_STATE, { type }) => {
switch (type) {
case ACTIONS.LOAD_BEGIN:
return INITIAL_STATE;
case ACTIONS.LOAD_END:
return { ...state, loading: false };
case ACTIONS.LOAD_ERROR:
return { ...state, loadError: true, loading: false };
default:
return state;
}
};
export { load, loadEnd, loadError };
export default reducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment