Skip to content

Instantly share code, notes, and snippets.

@mjstelly
Created July 5, 2020 17:36
Show Gist options
  • Save mjstelly/ecbbdfa94f50ad730e2d5339a1104ce4 to your computer and use it in GitHub Desktop.
Save mjstelly/ecbbdfa94f50ad730e2d5339a1104ce4 to your computer and use it in GitHub Desktop.
redux action fails
//calling module
import { setTab } from "../../../shared/store/actions/navAction";
<Tab
label={translate.tabAll}
selected={tab === 1}
onPress={() => {
setTab(1); //no console response when selected
}}
/>
// action types
export const SET_TAB = "SET_TAB";
//navAction
import { SET_TAB } from "./actionTypes";
export const setTab = (tab) => {
console.log("setTab action"); // log output
return async (dispatch) => {
console.log("setTab return"); // no log output
dispatch({
type: SET_TAB,
payload: tab,
});
};
};
//navReducer
import { SET_TAB } from "../../store/actions/actionTypes";
const initialState = {
selectedTab: 1,
};
export default (state = initialState, action) => {
switch (action.type) {
case SET_TAB:
return {
...state,
selectedTab: action.payload,
};
// blah blah... more cases
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment