* 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>
34 lines
913 B
TypeScript
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>
|
|
);
|
|
};
|