【发布时间】:2019-05-05 06:36:52
【问题描述】:
我有 index.js,这是一个没有类的 javascript 文件,它使用 RenderDOM 来渲染组件时间线并使用数据初始化一些数组,并且 index.js 有一个函数 playSound(),我已将 playSound 作为道具发送到时间线,但它返回错误 this.props.playSound is not a function。
对于不同的函数名称,即“playSound()”,它可以工作,但对于“onPlayFrames”,它不会在timeline.jsx 上被识别为函数
我这样发送道具:(index.js)
function onPlayFrames(arg){
// Code to play a sound with arg
}
ReactDOM.render(
<Timeline onPlayFrames={onPlayFrames}/>
,document.getElementById("root")
)
并像这样在时间轴上使用它:(timeline.jsx)
class Timeline extends React.Component {
constructor(props) {
super(props);
}
playStop(arg) {
this.props.onPlayFrames(arg);
}
}
当我尝试使用该功能时,我只是收到错误“this.state.onPlayFrames is not a function”,我做什么并不重要
【问题讨论】:
标签: javascript reactjs function