Skip to content
← Back to activity

Public problem

MGT React PeoplePicker throws `Cannot use 'in' operator` when `selectedPeople` starts as null

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

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?

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

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

Source: https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/1644