简体   繁体   English

Redux-React通过mapDispatchToProps方法传递对象

[英]Redux-React passing an object via the mapDispatchToProps method

I am passing an object via the mapDispatchToProps method on lines 214 and 249. The code executed on 214 seems fine but when I do the same thing on 249 it throws me the following error : 我通过214和249行上的mapDispatchToProps方法传递对象。在214上执行的代码似乎很好,但是当我在249上执行相同的操作时,它将引发以下错误:

Objects are not valid as a React child (found: object with keys {type, sound}). 对象作为React子对象无效(找到:带有键{type,sound}的对象)。

I don't really understand this error as I am new to redux and react. 我不太了解这个错误,因为我是Redux的新成员并做出了反应。 Could somebody help me resolve this issue using the redux state and maybe explain to me why it is wrong. 有人可以帮助我使用redux状态解决此问题,也许可以向我解释为什么它是错误的。 Thank you very much. 非常感谢你。

Here is a link to the code: 这是代码的链接:

//link to codepen
https://codepen.io/roger1891/pen/LaYYaN

You are returning this.props.addSound() , which returns an action creator object with its only argument sound as the data. 您将返回this.props.addSound() ,它返回一个action creator对象,其唯一的参数sound作为数据。 In this case the only argument you're passing in is mySoundList.localSoundList.map() . 在这种情况下,您要传递的唯一参数是mySoundList.localSoundList.map() You may just need to remove that function... 您可能只需要删除该功能...

return mySoundList.localSoundList.map((item) => {
      return (<div class="col-sm-4">
          <div id={item.btnId} class="btn btn-primary btn-sm drum-pad" onClick={this.clickButton} value={item.audioId}>
            {item.audioId}
            <audio id={item.audioId} class="clip" src={item.source} type={item.type}></audio>
          </div>
        </div>);                        
    });

Unless you're trying to do something asynchronously with the updated redux state from the ADD_Sound action? 除非您尝试对ADD_Sound操作中更新的redux状态进行异步处理?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM