Reactjs 在状态内部使用解构赋值 class BottomPanelProgramTabs扩展了React.Component{ 状态={ activeTab:this.props.children[0].props.label, }; ...

Reactjs 在状态内部使用解构赋值 class BottomPanelProgramTabs扩展了React.Component{ 状态={ activeTab:this.props.children[0].props.label, }; ...,reactjs,eslint,Reactjs,Eslint,ESLint想让我在上使用解构赋值 this.props.children[0].props.label 有什么办法吗?你可以这样做。 class BottomPanelProgramTabs扩展了React.Component{ 构造函数(){ 让[props]=this.props.children; 状态={ activeTab:props.label } } class BottomPanelProgramTabs extends React.Component<Props,

ESLint想让我在上使用解构赋值

this.props.children[0].props.label
有什么办法吗?

你可以这样做。

class BottomPanelProgramTabs扩展了React.Component{
构造函数(){
让[props]=this.props.children;
状态={
activeTab:props.label
}
}
class BottomPanelProgramTabs extends React.Component<Props, State> {
  constructor(){
        let [props] = this.props.children;
         state = {
          activeTab : props.label
         }

   }
 class BottomPanelProgramTabs extends React.Component<Props, State> {

  state = {
    activeTab: 'default label'
  };

  componentDidMount = () => {

    const [{ props: { label } }] = this.props.children;

    this.setState({
      activeTab: label || 'default label',
      ...
    })
  }

  ...