I have a function
export const setSearchField = text => dispatch => {
dispatch({ type: REQUEST_GIFS_PENDING });
fetch(API_URL + (text || DEFAULT_QUERY) + API_KEY + LIMIT)
.then(response => response.json())
.then(items =>
dispatch({ type: REQUEST_GIFS_SUCCESS, payload: items.data })
)
.catch(error => dispatch({ type: REQUEST_GIFS_FAILED, payload: error }));
};
Now i want to convert it to an async function, I did like this without try & catch, but its not working
export const setSearchField = text => dispatch => {
dispatch({ type: REQUEST_GIFS_PENDING });
async function fetUsers(){
const response = await fetch(API_URL + (text || DEFAULT_QUERY) + API_KEY + LIMIT);
const items = await response.json();
dispatch({ type: REQUEST_GIFS_SUCCESS, payload: items.data })
}
What am i doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…