Reactjs 为什么我总是使用class方法';组件安装';必须是';私人'';公共';或';受保护';警告,在我的tsx文件中?
我不确定应该在react类组件中标记哪些方法。我在以下方法中遇到此错误:componentDidMount、componentDidUpdate、componentWillUpdate和render 以下是我拥有的一个基本组件:Reactjs 为什么我总是使用class方法';组件安装';必须是';私人'';公共';或';受保护';警告,在我的tsx文件中?,reactjs,typescript,Reactjs,Typescript,我不确定应该在react类组件中标记哪些方法。我在以下方法中遇到此错误:componentDidMount、componentDidUpdate、componentWillUpdate和render 以下是我拥有的一个基本组件: import * as React from 'react'; const { Component } = React; export default class Loading extends Component<{}, {}> { compon
import * as React from 'react';
const { Component } = React;
export default class Loading extends Component<{}, {}> {
componentDidMount() {
console.log('....something....');
}
componentDidUpdate() {
console.log('....something....');
}
componentWillUpdate() {
console.log('....something....');
}
render() {
const style = {
background: '#f5f5f5',
height: '100%',
padding: '20px',
textAlign: 'center',
transition: 'all 0.5s linear',
width: '100%'
};
return (
<div id='app-loader' className='rounded' style={style}>
<div className='loader large block rounded'>Loading...</div>
</div>
);
}
}
import*as React from'React';
常数{Component}=React;
导出默认类加载扩展组件{
componentDidMount(){
console.log(“…某物…”);
}
componentDidUpdate(){
console.log(“…某物…”);
}
componentWillUpdate(){
console.log(“…某物…”);
}
render(){
常量样式={
背景:“#f5”,
高度:“100%”,
填充:“20px”,
textAlign:'中心',
过渡:“所有0.5s线性”,
宽度:“100%”
};
返回(
加载。。。
);
}
}
我无法放置private render()等,因为这会破坏组件。这是tslint规则
在tslint.json中,更改:
致:
我个人从未将此设置为仅
true
。在缺少访问修饰符的情况下,指定public
显然是浪费空间和增加混乱。还有一些类似的编译失败
错误,这些错误是由TSLint规则触发的,这些规则很容易知道:“接口名称”:[true,“从不使用前缀”]
:绕过接口名称必须以大写的I错误开头,“无空接口”:false
:允许声明空接口,“有序导入”:false
:不检查是否按字母顺序导入类只需在方法前面添加public
。
"member-access": true
"member-access": [true, "no-public"] // Or false. Read the rule and see what you want.