export const getLists = async (dispatch) => {
dispatch(getListsStart());
try {
const res = await axios.get("/lists", {
headers: {
token: "Bearer " + JSON.parse(localStorage.getItem("user")).accessToken,
},
});
dispatch(getListsSuccess(res.data));
} catch (err) {
dispatch(getListsFailure());
}
};
getListsStart
The code exports a function that takes an "async" parameter and returns a " Promise " object. The code starts by calling the "getListsStart()" function. This function calls the "axios" library to get a list of lists from the "http://api.github.com/repos/octocat/lists" endpoint. The "headers" property of the "res" object contains information about the request, including the "token" and "accessToken" values.
The "getListsSuccess" function accepts the "res.data" object as a parameter. This object contains the list data that was retrieved from the server. If there was any error while trying to get the list, the "getListsFailure" function is called instead.
Shortcut: getliststart.data
0 Comments
Add Comment
Log in to add a comment