Immutable solution version
MGT React PeoplePicker throws `Cannot use 'in' operator` when `selectedPeople` starts as null
Complete solution
How to fix microsoft graph: mgt react peoplepicker throws `cannot use 'in' operator` when `selectedpeople` starts as null.
Problem
I use the MGT React PeoplePicker with selectionMode='multiple' and pass an array of email addresses as selectedPeople. The picker renders with no names or pictures and throws: TypeError: Cannot use 'in' operator to search for 'groupTypes' in [email]. Passing Graph IDs instead of emails seems to be the documented usage, but emails should work too. What is wrong?
Verified fix
The error is not about emails vs IDs - it is a React state timing bug. selectedPeople was being populated after the initial render (e.g. via useState(null) then setGraphIds(others)), so on first render the picker received null and crashed when iterating over it. The fix, confirmed by the reporter: make sure the array is set before the picker first renders, so selectedPeople never starts as null. Initialize your state with the array (emails or IDs) up front, or do not render the picker until the array is populated.
Source: https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/1644
Evidence
Question: I use the MGT React PeoplePicker with selectionMode='multiple' and pass an array of email addresses as selectedPeople. The picker renders with no names or pictures and throws: TypeError: Cannot use 'in' operator to search for 'groupTypes' in [email]. Passing Graph IDs instead of emails seems to be the documented usage, but emails should work too. What is wrong?
Verified resolution: The error is not about emails vs IDs - it is a React state timing bug. selectedPeople was being populated after the initial render (e.g. via useState(null) then setGraphIds(others)), so on first render the picker received null and crashed when iterating over it. The fix, confirmed by the reporter: make sure the array is set before the picker first renders, so selectedPeople never starts as null. Initialize your state with the array (emails or IDs) up front, or do not render the picker until the array is populated.
Source: https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/1644
Thread: https://vectle.com/threads/thrZABAs3OOsiIjDrf1LurOw
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_xNLAhP1fSlqfFs9q4aqLLA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">MGT React PeoplePicker throws `Cannot use 'in' operator` when `selectedPeople` starts as null <span>— Vectle</span></a>