JS function won't return a return

Viewed 45

I am trying in Redux change state via action but when I try to fire up the action it won't return anything. I think there is SOME problem in return statement but not sure how it is. Everything before return works. If I put there any console.log it returns but if I put console.log after return it won't return anything.

I am calling setDir through mapDispatchProps.

I have try to look at some cases but can't find answer anywhere.

Action.js

export const setDir = (dir) => {
  const newDirection = dir === "asc" ? "desc" : "asc";
  return function (dispatch) {

    console.log(newDirection);
    dispatch({ type: SET_DIR, payload: newDirection });
  };
};

index.js

 const sortTable = (column) => {
  setColmn("val");
  setDir("desc");
  };
 <View style={styles.tableHeader}>
          {columns.map((column, index) => {
            {
              return (
                <TouchableOpacity
                  key={index}
                  style={styles.columnHeader}
                  onPress={() => sortTable(column)}
                >
                  <Text style={styles.columnHeaderTxt}>
                    {column + " "}
                    {selectedColumn === column && (
                      <AntDesign
                        size={20}
                        name={direction === "desc" ? "arrowdown" : "arrowup"}
                      />
                    )}
                  </Text>
                </TouchableOpacity>
              );
            }
          })}
        </View>
const mapDispatchProps = (dispatch) =>
  bindActionCreators({ fetchVoziky, setColmn, setDir }, dispatch);
1 Answers

Hii,
You should try to put it
const newDirection = dir === "asc" ? "desc" : "asc";
before the console.log or inside the return.

Related