Change to using arrow functions (#1603)
* Change to using arrow functions Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Add lint rule --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import { type RecoilScopeContext as RecoilScopeContextType } from '@/types/Recoi
|
||||
|
||||
import { RecoilScopeContext } from '../states/RecoilScopeContext';
|
||||
|
||||
export function RecoilScope({
|
||||
export const RecoilScope = ({
|
||||
children,
|
||||
scopeId,
|
||||
CustomRecoilScopeContext,
|
||||
@@ -13,7 +13,7 @@ export function RecoilScope({
|
||||
children: React.ReactNode;
|
||||
scopeId?: string;
|
||||
CustomRecoilScopeContext?: RecoilScopeContextType;
|
||||
}) {
|
||||
}) => {
|
||||
const currentScopeId = useRef(scopeId ?? v4());
|
||||
|
||||
return CustomRecoilScopeContext ? (
|
||||
@@ -25,4 +25,4 @@ export function RecoilScope({
|
||||
{children}
|
||||
</RecoilScopeContext.Provider>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Context, useContext } from 'react';
|
||||
|
||||
export const useContextScopeId = (SpecificContext: Context<string | null>) => {
|
||||
const recoilScopeId = useContext(SpecificContext);
|
||||
|
||||
if (!recoilScopeId)
|
||||
throw new Error(
|
||||
`Using useContextScopedId outside of the specified context : ${SpecificContext.displayName}, verify that you are using a RecoilScope with the specific context you want to use.`,
|
||||
);
|
||||
|
||||
return recoilScopeId;
|
||||
};
|
||||
@@ -2,7 +2,7 @@ import { useContext } from 'react';
|
||||
|
||||
import { RecoilScopeContext } from '@/types/RecoilScopeContext';
|
||||
|
||||
export function useRecoilScopeId(RecoilScopeContext: RecoilScopeContext) {
|
||||
export const useRecoilScopeId = (RecoilScopeContext: RecoilScopeContext) => {
|
||||
const recoilScopeId = useContext(RecoilScopeContext);
|
||||
|
||||
if (!recoilScopeId)
|
||||
@@ -11,4 +11,4 @@ export function useRecoilScopeId(RecoilScopeContext: RecoilScopeContext) {
|
||||
);
|
||||
|
||||
return recoilScopeId;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,11 +3,11 @@ import { RecoilState, useRecoilState } from 'recoil';
|
||||
|
||||
import { RecoilScopeContext } from '../states/RecoilScopeContext';
|
||||
|
||||
export function useRecoilScopedFamilyState<StateType>(
|
||||
export const useRecoilScopedFamilyState = <StateType>(
|
||||
recoilState: (familyUniqueId: string) => RecoilState<StateType>,
|
||||
uniqueIdInRecoilScope: string,
|
||||
CustomRecoilScopeContext?: Context<string | null>,
|
||||
) {
|
||||
) => {
|
||||
const recoilScopeId = useContext(
|
||||
CustomRecoilScopeContext ?? RecoilScopeContext,
|
||||
);
|
||||
@@ -22,4 +22,4 @@ export function useRecoilScopedFamilyState<StateType>(
|
||||
const familyUniqueId = recoilScopeId + uniqueIdInRecoilScope;
|
||||
|
||||
return useRecoilState<StateType>(recoilState(familyUniqueId));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,10 +3,10 @@ import { RecoilState, useRecoilState } from 'recoil';
|
||||
|
||||
import { RecoilScopeContext } from '../states/RecoilScopeContext';
|
||||
|
||||
export function useRecoilScopedState<StateType>(
|
||||
export const useRecoilScopedState = <StateType>(
|
||||
recoilState: (param: string) => RecoilState<StateType>,
|
||||
CustomRecoilScopeContext?: Context<string | null>,
|
||||
) {
|
||||
) => {
|
||||
const recoilScopeId = useContext(
|
||||
CustomRecoilScopeContext ?? RecoilScopeContext,
|
||||
);
|
||||
@@ -19,4 +19,4 @@ export function useRecoilScopedState<StateType>(
|
||||
);
|
||||
|
||||
return useRecoilState<StateType>(recoilState(recoilScopeId));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,10 +3,10 @@ import { RecoilState, RecoilValueReadOnly, useRecoilValue } from 'recoil';
|
||||
|
||||
import { RecoilScopeContext } from '../states/RecoilScopeContext';
|
||||
|
||||
export function useRecoilScopedValue<T>(
|
||||
export const useRecoilScopedValue = <T>(
|
||||
recoilState: (param: string) => RecoilState<T> | RecoilValueReadOnly<T>,
|
||||
CustomRecoilScopeContext?: Context<string | null>,
|
||||
) {
|
||||
) => {
|
||||
const recoilScopeId = useContext(
|
||||
CustomRecoilScopeContext ?? RecoilScopeContext,
|
||||
);
|
||||
@@ -19,4 +19,4 @@ export function useRecoilScopedValue<T>(
|
||||
);
|
||||
|
||||
return useRecoilValue<T>(recoilState(recoilScopeId));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user