Files
twenty/packages/twenty-front/src/modules/context-store/components/MainContextStoreComponentInstanceIdSetterEffect.tsx
T
Raphaël Bosi a9cb1e9b0d Refactor actions (#8761)
Closes #8737 
- Refactored actions by creating hooks to add the possibility to
register actions programatically.
- Small fixes from #8610 review
- Fixed shortcuts display inside the command menu
- Removed `actionMenuEntriesComponentState` and introduced
`actionMenuEntriesComponentSelector`
2024-11-27 15:08:27 +01:00

28 lines
1.0 KiB
TypeScript

import { CONTEXT_STORE_INSTANCE_ID_DEFAULT_VALUE } from '@/context-store/constants/ContextStoreInstanceIdDefaultValue';
import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';
import { mainContextStoreComponentInstanceIdState } from '@/context-store/states/mainContextStoreComponentInstanceId';
import { useContext, useEffect } from 'react';
import { useSetRecoilState } from 'recoil';
export const MainContextStoreComponentInstanceIdSetterEffect = () => {
const setMainContextStoreComponentInstanceId = useSetRecoilState(
mainContextStoreComponentInstanceIdState,
);
const context = useContext(ContextStoreComponentInstanceContext);
useEffect(() => {
setMainContextStoreComponentInstanceId(
context?.instanceId ?? CONTEXT_STORE_INSTANCE_ID_DEFAULT_VALUE,
);
return () => {
setMainContextStoreComponentInstanceId(
CONTEXT_STORE_INSTANCE_ID_DEFAULT_VALUE,
);
};
}, [context, setMainContextStoreComponentInstanceId]);
return null;
};