具有功能组件的功能道具-不是功能(React + Typescript)

时间:2020-04-30 10:08:17

标签: reactjs typescript

我有一个功能组件,其功能道具不起作用。所以...

export interface IPanelProps {
  itemID; number;
  Open: boolean;
  onClose: () => void;
}


const FabricPanel: FC<IPanelProps> = ({ onClose, Open, itemID }) => {
  let _OnCancelClick = () => {
    onClose();
  }

  return (
    <Panel isOpen={Open}>
      <h2>{itemID} </h2>
      <DialogFooter>
        <DefaultButton text="Cancel" onClick={_OnCancelClick} />
        <PrimaryButton text="Save" />
      </DialogFooter>
    </Panel>
  )
}

获取错误: 未捕获的TypeError:onClose不是函数 Open和Item ID道具运行良好,是因为我正在调用功能道具吗?我试图放(道具)代替,这没有用。

有什么想法吗?

在父组件上:

   _renderPanelComponent = (props: any) => {
    const element : React.ReactElement<IPanelProps> = React.createElement(FabricPanel, assign({
      itemID : null,
      Open : false,
      OnClose : null


    }, props))
    ReactDom.render(element, this.panelPlaceHolder);
  }

  _showPanel = (itemID : number) => {
    this._renderPanelComponent({
      itemID,
      Open : true,
      OnClose : this._dismissPanel


    })
  }

  _dismissPanel = () =>{        
    this._renderPanelComponent({ isOpen: false });   
 }

在SharePoint上按下按钮时,将执行箭头功能Showpanel,这可以正常工作。但是onClose无效。

1 个答案:

答案 0 :(得分:0)

OnClose在功能组件和父组件之间的拼写有所不同。因此,两者都拼写为onClose-已排序!