CreateComponentFamilyState -> createComponentFamilyStateV2 (#11546)
Refacto of createComponentFamilyState --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { ComponentFamilySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilySelectorV2';
|
||||
import { ComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/types/ComponentFamilyStateV2';
|
||||
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
|
||||
import { SerializableParam, useRecoilState } from 'recoil';
|
||||
@ -7,7 +8,9 @@ export const useRecoilComponentFamilyStateV2 = <
|
||||
StateType,
|
||||
FamilyKey extends SerializableParam,
|
||||
>(
|
||||
componentState: ComponentFamilyStateV2<StateType, FamilyKey>,
|
||||
componentState:
|
||||
| ComponentFamilyStateV2<StateType, FamilyKey>
|
||||
| ComponentFamilySelectorV2<StateType, FamilyKey>,
|
||||
familyKey: FamilyKey,
|
||||
instanceIdFromProps?: string,
|
||||
) => {
|
||||
@ -26,5 +29,10 @@ export const useRecoilComponentFamilyStateV2 = <
|
||||
instanceIdFromProps,
|
||||
);
|
||||
|
||||
return useRecoilState(componentState.atomFamily({ instanceId, familyKey }));
|
||||
const familySelector =
|
||||
componentState.type === 'ComponentFamilyState'
|
||||
? componentState.atomFamily({ instanceId, familyKey })
|
||||
: componentState.selectorFamily({ instanceId, familyKey });
|
||||
|
||||
return useRecoilState(familySelector);
|
||||
};
|
||||
|
||||
@ -16,6 +16,7 @@ export function createComponentFamilySelectorV2<
|
||||
>(options: {
|
||||
key: string;
|
||||
get: SelectorGetter<ValueType, ComponentFamilyStateKeyV2<FamilyKey>>;
|
||||
set?: never;
|
||||
componentInstanceContext: ComponentInstanceStateContext<any> | null;
|
||||
}): ComponentFamilyReadOnlySelectorV2<ValueType, FamilyKey>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user