英文:
How to clear the MGT PeoplePicker in react hooks SPFx web part?
问题
需要在使用后清除 PeoplePicker
。
<PeoplePicker
selectedPeople={addedMembers}
selectionMode={"multiple"}
show-max={50}
selectionChanged={onPeoplePickerChanged}
/>;
所以我将 addedMembers
设置为 []
,但它不起作用。
我看到一个涉及到 ref 的答案 这里,但它使用了类,而我只知道 hooks。
有人可以帮忙吗?
谢谢
英文:
I need to clear the the PeoplePicker
after use.
<PeoplePicker
selectedPeople={addedMembers}
selectionMode={"multiple"}
show-max={50}
selectionChanged={onPeoplePickerChanged}
/>;
So I set addedMembers
to []
but it does not work.
I saw an answer involving ref here but it uses a class and I only know hooks.
Anyone can help?
Thank you
答案1
得分: 1
看例子 https://stackblitz.com/edit/react-ts-zayywf?file=App.tsx
创建一个引用 const ppl = React.useRef(null);
添加到 <PeoplePicker ref={ppl}
然后当你想要清除时,将 selectedPeople 设置为 [] 并运行 ppl.current.focus();
希望能帮助其他人
英文:
See example https://stackblitz.com/edit/react-ts-zayywf?file=App.tsx
make a ref const ppl = React.useRef(null);
add to the <PeoplePicker ref={ppl}
then when you want to clear set the selectedPeople to [] and run ppl.current.focus();
Hope it helps others
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论