小编Cou*_*ntD的帖子

Next Js & Typescript - 类型示例中不存在属性 setState

代码工作正常,但我不知道如何在 VSCode 中删除此错误。感谢帮助。

import * as React from 'react';

interface State {
  text: string;
}
export default class Example extends React.Component<State> {
 state: State = {
    text: 'SOME TEXT'
}

private handleChange = () => {
    this.setState({text: 'New Text'}); //error: property setState does not exist on type Example
}

public render(){
    return(
        <div>
        <h2 onClick={this.handleChange}>{this.state.text}</h2>
        </div>
    )
 }
}
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs babeljs nextjs

4
推荐指数
2
解决办法
6998
查看次数

标签 统计

babeljs ×1

javascript ×1

nextjs ×1

reactjs ×1

typescript ×1