首页 > 解决方案 > 如何在 tsx 中将道具传递给孩子?

问题描述

当我将道具传递给孩子时,我有一个错误“属性'isClicked'不存在于类型'IntrinsicAttributes & IntrinsicClassAttributes”我写了“isClicked?:布尔”。我还应该做什么?

export interface DropDownProperties extends ComponentBaseProperties {
  multiSelect?: boolean;
  IconTextColor?:string;
  isClicked?: boolean;
}

export interface DropDownState extends ComponentBaseState {
  dropDownOptions: DropDownItem[];
  isOpen: boolean;
  results: string[];
  isClicked?: boolean;
 
}
export default class DropDown extends ComponentBase<
  DropDownProperties,
  DropDownState
> { return ( <DropDownItem
          iconName={option.iconName}
          value={option.value}
          displayValue={option.displayValue ? true : false}
          key={option.name}
          onClick={(e) => this.optionSelected()}
          isClicked={this.state.isOpen}
        >
          {option.props.children}
        </DropDownItem>
      ))}
       </ul>
      );
    }
  };

标签: reactjstypescripttsx

解决方案


如果您在组件中使用连接,则使用以下代码应该可以解决问题。

export default connect<{}, {}, Props>(..........)

这里connect有 3 个参数,第三个参数是 interface Props,它有你想要输入的变量。


推荐阅读