Forum Discussion
How to blank a People Picker (PnP, spfx, react)
- Nov 18, 2019
I think you should be evaluating the items object and not the state as you are using that function to set the state
Have you tried something like:
if(items !== null && items.length > 0){
Joel Rodrigues Hi Joel,
Yes you are right - but I'm struggling to find a way to evaluate it as blank. When removing the user from the PP, it's always evaluating as not null. This is what I'm trying now but it's still evaluating as not null:
private _deptContGetPeoplePickerItems(items) {
if(this.state.DeptContact !== null){
console.log('Dept Contact not null');
this.setState({
DeptContact: items[0].id,
DeptContactPPDefaultItems: [items[0].secondaryText],
});
} else if(this.state.DeptContact){
console.log('Dept Contact is null');
}
}
Do I have to use an async await so when the a user clicks to blank the pp, it waits for the state to empty, then the if can run?
If so...how?
T
I think you should be evaluating the items object and not the state as you are using that function to set the state
Have you tried something like:
if(items !== null && items.length > 0){
- Cardinal_NightNov 18, 2019Brass Contributor
Joel Rodrigues - thanks Joel. That was one of those that has been bugging me for a while. I got close to your answer at one point but took the wrong direction and hit a dead end. Thanks again.