I am creating a SPFx web part with React and I am using the Microsoft Graph Toolkit PeoplePicker. It offers a selectionChanged
callback. This callback gets passed a parameter of type Event
(defined in typescript/lib/lib.dom.d.ts
)
export type PeoplePickerProps = {
// ....
selectionChanged?: (e: Event) => void;
}
However, according to this documentation I need to access event.target.selectedPeople
. But selectedPeople
does not exist as property of event.target
.
My code looks like this:
import * as React from 'react';
import { PeoplePicker, People } from '@microsoft/mgt-react/dist/es6/spfx';
export const EmployeePicker: React.FC = (): React.ReactElement => {
const [people, setPeople] = React.useState([]);
const handleSelectionChanged = (event: Event): void => {
console.log('Selection changed');
console.log('event', event);
setPeople(event.target.selectedPeople);
};
return (
<div>
<PeoplePicker selectionChanged={handleSelectionChanged} />
Selected People:
<People people={people} />
</div>
);
};
I'd like to avoid opting out of the type system. (I guess changing the type of event
to any
would work) And rather know how I can access the event.target.selectedPeople
prop using typescripts type system.