首页 > 解决方案 > Office ui Fabric People Picker,将变量传递给 onChangeEvent

问题描述

我想知道是否有可能将变量添加到 office ui fabric react People Picker 组件的默认 onchange 事件中。

在 onchange 事件中默认是onChange?: (items?: IPersonaProps[]) => void

我想传递一个变量以添加到像键值这样的数组中,以便稍后在我的代码中使用。

标签: reactjsspfxoffice-ui-fabricpeoplepicker

解决方案


您可以构建一个 HOC 来实现这一点。

定义

// 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
  ...

用法


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

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

推荐阅读