
[英]why <button onClick={this.props.onClick}> is different from <button onClick={(e) => {this.props.onClick(e)}}> here?
[英]Uncaught TypeError: _this.props.onClick is not a function
我新手react
,并尝试建立一个api
。 我的问题是我使用onClick
函数从子节点传递给父组件的props
是抛出错误。 我甚至尝试使用这个关键字,但我无法弄清楚发生了什么问题。
我发现我的StockContent
组件没有收到我从body组件传递的showOverlay
道具
我打算通过使用onClick功能更改它来导航到当前的点击内容。
整个项目都在这里...... https://github.com/Kushan-/stockStimulation
{
import React from 'react';
import ReactDOM from 'react-dom';
import StockContent from '../bodyRoutes/StockContent.js'
import ShareOverlay from '../bodyRoutes/SharesOverlay.jsx'
const pushState = (obj, url) => window.history.pushState(obj, '', url);
class Main extends React.Component{
state = {
content: []
}
componentDidMount(){
$.ajax({
url: '/data',
context: this,
dataType: 'json',
type: 'GET'
}).done(function (res) {
console.log(res)
this.setState({
content:res
});
})
}
componentWillUnmount(){
//clean timers, listners
}
fetchStock = (stockName, stockId) => {
const url = '/'+stockName+'/'+stockId;
const obj = {currentStockName : stockName, currentStockId : stockId}
pushState(obj,url);
this.setState({
currentStockName: stockName,
currentStockId: stockId
})
};
displayPop(){
if(this.state.currentStockId) {
console.log(this.state.content[this.state.currentStockId]);
const data= this.state.content[this.state.currentStockId];
return(<div className="row" ><ShareOverlay stockData={data}/></div>)
}
return(<StockContent showOverlay={this.fetchContent} content={this.state.content}/>)
}
render(){
return(
<div>
{this.displayPop()}
</div>
)
}
}
export default Main;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.