import React,{Component} from 'react';
type PropsType={}
type StateType={
showText:string
}
class TestPage extends Component<PropsType,StateType>{
constructor(props){
super(props);
this.state={
showText:""
}
}
render(){
return <div>
<div>{this.state.showText}</div>
</div>
}
}
React中class中读取state
最新推荐文章于 2025-12-02 16:49:34 发布
文章展示了如何在React中创建一个名为TestPage的类组件,定义了PropsType和StateType接口来约束props和state的类型。初始化状态包含一个空字符串showText,该值在render方法中被渲染到页面上。
514

被折叠的 条评论
为什么被折叠?



