【问题标题】:Office ui Fabric People Picker, pass varaibles to onChangeEventOffice ui Fabric People Picker,将变量传递给onChange事件
【发布时间】:2020-05-27 17:21:04
【问题描述】:
我想知道是否有可能向 office ui fabric react People Picker 组件的默认 onchange 事件添加一个变量。
在 onchange 事件中默认是onChange?: (items?: IPersonaProps[]) => void
我想传递一个变量以添加到像键值这样的数组中,以便稍后在我的代码中使用。
【问题讨论】:
标签:
reactjs
spfx
office-ui-fabric
peoplepicker
【解决方案1】:
您可以构建一个 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()}
...