为什么我要继续获取在我的tsx文件中,类方法'componentDidMount'必须标记为'private''public'或'protected'警告?

问题描述 投票:11回答:1

我不确定我应该在反应类组件中标记我的方法。我在这些方法上收到此错误:componentDidMount,componentDidUpdate,componentWillUpdate和render

这是我的基本组件:

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>
    );
  }
}

我不能把私有render()等因为破坏组件。

reactjs typescript
1个回答
20
投票

这是tslint member-access规则。

在tslint.json中,更改:

"member-access": true

至:

"member-access": [true, "no-public"] // Or false. Read the rule and see what you want.
© www.soinside.com 2019 - 2024. All rights reserved.