React-redux 将值传递给 url 以进行 gif 搜索 [英] React-redux passing a value to url for gif search

查看:36
本文介绍了React-redux 将值传递给 url 以进行 gif 搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这个反应应用

I have created this react app https://ssayanm.github.io/giphy-redux/ , used redux, now I want to change the result gif's based on the search field, currently, I cannot pass the value to my query string via api.

I have logger added, I can see that the payload is showing the "Search box" input value but how to pass that value.

Github repo: https://github.com/ssayanm/giphy-redux

Thank you

解决方案

You need to update function setSearchField:

export const setSearchField = text => dispatch => {
  dispatch({ type: REQUEST_GIFS_PENDING });
  fetch(API_URL + text + API_KEY + LIMIT)
    .then(response => response.json())
    .then(items =>
      dispatch({ type: REQUEST_GIFS_SUCCESS, payload: items.data })
    )
    //.fetch(API_URL + dispatch. + API_KEY + LIMIT)
    .catch(error => dispatch({ type: REQUEST_GIFS_FAILED, payload: error }));
};

See live example:

这篇关于React-redux 将值传递给 url 以进行 gif 搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆