Skip to content

Commit

Permalink
🐛 Fix Shadcn/ui lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
kich555 committed Jul 7, 2024
1 parent 249dafb commit a9c4604
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ module.exports = {
'no-console': 'error',
'react/jsx-props-no-spreading': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error', { variables: false, functions: false, classes: false }],
'react/jsx-no-constructed-context-values': 'off',
'@typescript-eslint/no-use-before-define': ['off'],
},
settings: {
react: {
Expand Down
6 changes: 4 additions & 2 deletions src/components/ui/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ type FormFieldContextValue<TFieldValues extends FieldValues = FieldValues, TName
const FormFieldContext = React.createContext<FormFieldContextValue>({} as FormFieldContextValue);

function FormField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) {
const value = React.useMemo(() => ({ name: props.name }), [props.name]);
return (
<FormFieldContext.Provider value={{ name: props.name }}>
<FormFieldContext.Provider value={value}>
<Controller {...props} />
</FormFieldContext.Provider>
);
Expand Down Expand Up @@ -53,8 +54,9 @@ const FormItemContext = React.createContext<FormItemContextValue>({} as FormItem

const FormItem = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => {
const id = React.useId();

return (
// NOTE: React.useId()이기 때문에 useMemo로 감쌀 필요가 없음
// eslint-disable-next-line react/jsx-no-constructed-context-values
<FormItemContext.Provider value={{ id }}>
<div ref={ref} className={cn('space-y-2', className)} {...props} />
</FormItemContext.Provider>
Expand Down

0 comments on commit a9c4604

Please sign in to comment.