Office ui Fabric People Picker, pass varaibles to onChangeEvent

时光毁灭记忆、已成空白 提交于 2020-04-30 11:44:49

问题


I would like to know if there is a possibility to added a variable to the default onchange event of the office ui fabric react People Picker component.

In the onchange event default is onChange?: (items?: IPersonaProps[]) => void

I would like to pass an variable to add to an array like Key Value for using later in my code.


回答1:


You can build a HOC to achieve this.

Define

// Your HOC component

interface Props {
  yourCustomState: string // get custom value from props
...


return (
  <>
    <Select
      onChange={(e: any) => onChange(e, yourCustomState)} // add custom value to callBack function
  ...

Usage


handleOnChangeEvent = () => (event, yourCustomStateValue: string) => {
  console.log(yourCustomStateValue);
  ... // event
}

<YourComponent
  yourCustomState={value}
  onChange={this.handleOnChangeEvent()}
...


来源:https://stackoverflow.com/questions/60183462/office-ui-fabric-people-picker-pass-varaibles-to-onchangeevent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!