react报错this.setState is not a function

当报错这个的时候就要看函数是否在行内绑定this,或者在constructor中绑定this。

我这里犯的错误的是虽然我在constructor中绑定了this,但是语法写的不正确。

错误示范:

复制代码
constructor(props){
    super(props);
    this.state = {
        keyword:this.props.match.params.id,
        result:"true",
        _isMounted:true
    };
    this.handleFetch.bind(this)  //看这里
}
复制代码

正确写法:

复制代码
constructor(props){
    super(props);
    this.state = {
        keyword:this.props.match.params.id,
        result:"true",
        _isMounted:true
    };
    this.handleFetch=this.handleFetch.bind(this)  //这里一定要写等于
}
复制代码

问题见这里:https://segmentfault.com/q/1010000015903657

posted @   蓓蕾心晴  阅读(1216)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示