- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从我的“扫描仪”组件中获取 componentWillMount() 中的 JSON 数据,如下所示:
async componentWillMount() {
const url = 'https://foo.com/products/product1.json';
fetch(url)
.then((response) => response.json())
.then((responseData) => this.props.dispatchProductLoad())
.catch(error => {
console.log(error);
});
}
下面是我的发送代码:
function mapDispatchToProps(dispatch) {
return { dispatchProductLoad: () => dispatch(productLoad(SOMEDATA)) };
};
export default connect(null, mapDispatchToProps)(Scanner);
变量 SOMEDATA 应该保存来自 responseData 的值(目前它还没有定义)
所以我的问题是 - 如何将 SOMEDATA 的值设置为 responseData 中保存的值?
最佳答案
您可以使用 responseData
作为参数调用 action creator 并定义您的 mapDispatchToProps
函数
async componentWillMount() {
const url = 'https://foo.com/products/product1.json';
fetch(url)
.then((response) => response.json())
.then((responseData) => this.props.dispatchProductLoad(responseData))
.catch(error => {
console.log(error);
});
}
function mapDispatchToProps(dispatch) {
return { dispatchProductLoad: (response) => dispatch(productLoad(response)) };
};
export default connect(null, mapDispatchToProps)(Scanner);
关于react-native - React Native、Fetch 和 Dispatch : How do I access responseData within mapDispatchToProps()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49034706/
我正在发出异步请求,并且在 [responseData setLength:0]; 上收到 EXC_BAD_ACCESS 代码是: - (void)connection:(NSURLConnectio
这是我在 stackoverflow 上的第一篇文章,所以我希望我不会犯太多错误。 我在填充 Java 列表并将其发送到 aui:select 作为选项时遇到问题。我的目标是在其中一个选项发生更改时动
我只是在玩 Alamofire 框架并进行很少的 api 调用。但是我观察到 alamofire 中有两种请求方法 Alamofire 的 responseJSON 和 responseData 有什
我有一个问题,我不想检查 URL 的 statusCode(如果页面或文件存在),我想知道状态是否等于 200。所以我使用这个函数: Alamofire.request(Configu
当我向我的网络服务器请求时,它会在 request.response 中向我发送 Json 字符串。我想将该 json 存储到 NSDictionary 中以进行解析并将其存储到数据库中。我的 Jso
我在 stackoverflow 上找到了很多关于设置对我的服务器的 HTTP POST 请求的好建议。我遵循了很多例子。我在一个项目中设置了一个快速测试,试图发送一个 POST 请求并从服务器检索一
当我运行代码时,结果是这样的:类型错误:“NoneType”对象不可订阅 我是Python初学者。我刚刚从 Python 初学者网站上挑选了一个示例项目:https://www.pythonforbe
我正在尝试使用 Python 和 simplejson 截屏 Google 搜索的第一个结果,但我无法像许多在线示例演示的那样访问搜索结果。这是一个片段: url = 'http://ajax.goo
我正在使用 Jackson 库创建 JSON 对象,但是当我使用 mapper.writeValue(System.out, responseData) 函数时,程序终止。这是我的代码: import
我正在从我的“扫描仪”组件中获取 componentWillMount() 中的 JSON 数据,如下所示: async componentWillMount() { const url = 'h
我是一名优秀的程序员,十分优秀!