Reactjs 反冲:设置atomFamily时,父状态不更新

Reactjs 反冲:设置atomFamily时,父状态不更新,reactjs,recoiljs,Reactjs,Recoiljs,我有一个React功能组件订阅了一个反冲原子家族。其目的是atomFamily将更新父状态中的一个项,然后根据父状态的另一个组件将通过useffect重新渲染。然而,这似乎没有发生。为什么会这样?从它看起来的样子(以及我自己的实验)来看,使用反冲选择器更改父状态的一部分应该会自动传播回父状态 选择器状态项如下所示: 从“反冲”导入{atomFamily,selectorFamily}; 从“/../interfaces/GroupInterface”导入{GroupInterface}; 从“/

我有一个React功能组件订阅了一个反冲原子家族。其目的是atomFamily将更新父状态中的一个项,然后根据父状态的另一个组件将通过
useffect
重新渲染。然而,这似乎没有发生。为什么会这样?从它看起来的样子(以及我自己的实验)来看,使用反冲选择器更改父状态的一部分应该会自动传播回父状态

选择器状态项如下所示:

从“反冲”导入{atomFamily,selectorFamily};
从“/../interfaces/GroupInterface”导入{GroupInterface};
从“/GroupList”导入{GroupList};
导出常量GroupSelector=atomFamily({
键:“组选择器”,
默认值:selectorFamily({
键:“GroupSelector/default”,
get:id=>({get}):GroupInterface=>{
const groupList=get(groupList);
返回groupList.find((group)=>group.id==id)作为GroupInterface
}
})
})
父状态项如下所示:

从“反冲”导入{atom};
从“../interfaces/GroupInterface”导入{GroupInterface};
export const GroupList=atom({
关键字:“组列表”,
默认值:[]作为GroupInterface[]
})
设置atomFamily后需要更新的组件如下所示:

useffect(()=>{
setCurrentActiveSwaps(getCurrentActiveSwaps(groupList));
//eslint禁用下一行
},[groupList])

首先,您为GroupSelector分配了一个atomFamily

GroupSelector = atomFamily({
然后将该原子的默认值设置为selectorFamily

 default: selectorFamily({
通常,默认值为数组或对象。使用selectorFamily作为默认值很有趣,但不确定它将引导到哪里

这是一个很好的例子


首先,您为GroupSelector分配了一个atomFamily

GroupSelector = atomFamily({
然后将该原子的默认值设置为selectorFamily

 default: selectorFamily({
通常,默认值为数组或对象。使用selectorFamily作为默认值很有趣,但不确定它将引导到哪里

这是一个很好的例子