小编dav*_*ave的帖子

如何使用 redux-saga 传递参数

作为 react-native 和 redux-saga 的练习,我正在尝试开发一个小天气应用程序。

虽然获取和呈现数据工作正常,但我以某种方式难以将参数从 TextInput 传递到最终的 API 调用。

现在的目标只是将 cityName 字符串传递给 api.js 和 console.log 中的 fetchWeather 函数。

props.requestWeather(cityName)Main.js 内部开始

我尝试了各种方法通过 action 和 saga 将 cityName 传递给 apiCall,这让我意识到,我比其他任何事情都在猜测。遗憾的是,以下研究也没有成功,所以我们来了。

关于如何将字符串作为参数传递和/或对以下 redux 设置的一般批评的任何想法都将受到高度赞赏!

戴夫

主程序

//[...] setCity Name to TextInput component
const [cityName, setCityName] = useState('')   
// [...] calling the action (inside onClickHandler)
props.requestWeather() 
//[...] 
const mapStateToProps = state => ({
    weatherData: state.weatherData
});

const mapDispatchToProps = dispatch =>
    bindActionCreators({ requestWeather }, dispatch);

export default connect(mapStateToProps, mapDispatchToProps)(Main);
Run Code Online (Sandbox Code Playgroud)

动作.js

export …
Run Code Online (Sandbox Code Playgroud)

react-native redux redux-saga

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

react-native ×1

redux ×1

redux-saga ×1