Files
twenty_crm/front/src/modules/ui/utilities/recoil-scope/components/RecoilScope.tsx
gitstart-twenty 0c79217ba0 Add an ESLint rule to prevent the usage of useRef other than for HTML elements. (#2014)
* Add an ESLint rule to prevent the usage of useRef other than for HTML elements

Co-authored-by: v1b3m <vibenjamin6@gmail.com>

* Bump eslint version and rewrite rule

* Fix

---------

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
2023-10-14 11:32:46 +02:00

34 lines
913 B
TypeScript

import { useRef } from 'react';
import { v4 } from 'uuid';
import { RecoilScopeContext as RecoilScopeContextType } from '@/types/RecoilScopeContext';
import { RecoilScopeContext } from '../states/RecoilScopeContext';
/**
*
* @deprecated Use a custom scope context instead, see example with DropdownScope
*/
export const RecoilScope = ({
children,
scopeId,
CustomRecoilScopeContext,
}: {
children: React.ReactNode;
scopeId?: string;
CustomRecoilScopeContext?: RecoilScopeContextType;
}) => {
// eslint-disable-next-line twenty/no-state-useref
const currentScopeId = useRef(scopeId ?? v4());
return CustomRecoilScopeContext ? (
<CustomRecoilScopeContext.Provider value={currentScopeId.current}>
{children}
</CustomRecoilScopeContext.Provider>
) : (
<RecoilScopeContext.Provider value={currentScopeId.current}>
{children}
</RecoilScopeContext.Provider>
);
};