[WIP]πstories λ΄ render ν¨μκ° React μ»΄ν¬λνΈκ° μλ μΌλ° ν¨μλ‘ μΈμλμ΄ useState ν
νΈμΆμ΄ κΈμ§λμ΄ λ°μνλ μ€λ₯
2025. 10. 27. 14:21γTrouble Shooting & Issues/Linkiving
λ°μν
TextField.stories.tsx
import type { Meta, StoryObj } from '@storybook/react';
import React, { useState } from 'react';
import Image from '../../../public/icons/Image';
import TextField from './TextField';
const meta: Meta<typeof TextField> = {
title: 'Components/TextField',
component: TextField,
tags: ['autodocs'],
argTypes: {
size: {
control: { type: 'select' },
options: ['sm', 'md', 'lg'],
},
radius: {
control: { type: 'select' },
options: ['none', 'sm', 'md', 'lg'],
},
variant: {
control: { type: 'select' },
options: ['outline', 'filled'],
},
disabled: {
control: { type: 'boolean' },
},
},
};
export default meta;
type Story = StoryObj<typeof TextField>;
export const Default: Story = {
render: args => {
const [value, setValue] = useState('');
return <TextField {...args} value={value} onChange={e => setValue(e.target.value)} />;
},
args: {
placeholder: 'Enter text...',
size: 'md',
radius: 'md',
variant: 'outline',
icon: <Image src="file.svg" alt="img" />,
disabled: false,
},
};
error
34:31 Error: React Hook "useState" is called in function "render" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use". react-hooks/rules-of-hooks
ESLint react-hooks/rules-of-hooks κ·μΉμ μν΄ Storybook μ€ν 리 λ΄ render ν¨μκ° React μ»΄ν¬λνΈκ° μλ μΌλ° ν¨μλ‘ μΈμλμ΄ useState ν νΈμΆμ΄ κΈμ§λμ΄ λ°μνλ μ€λ₯μ λλ€.
ν° κ΅¬μ‘° λ³κ²½ μμ΄ μ€λ₯λ₯Ό νΌνλ κ°λ¨ν λ°©λ²
render ν¨μμμ λ°λ‘ ν μ νΈμΆνμ§ λ§κ³ , ν μ μ¬μ©νλ μ»΄ν¬λνΈλ₯Ό ν¨μ μ μΈλ¬ΈμΌλ‘ λ°λ‘ λ§λ€μ΄μ renderμμ νΈμΆνλ λ°©μμ λλ€.
import React, { useState } from 'react';
function ControlledTextField(args: typeof TextField extends React.ComponentType<infer P> ? P : never) {
const [value, setValue] = useState('');
return <TextField {...args} value={value} onChange={e => setValue(e.target.value)} />;
}
export const Default: Story = {
render: args => <ControlledTextField {...args} />,
args: {
placeholder: 'Enter text...',
size: 'md',
radius: 'md',
variant: 'outline',
icon: <Image src="file.svg" alt="img" />,
disabled: false,
},
};
SearchInput.stories.tsx
export const Default: Story = {
render: args => {
const [value, setValue] = useState('');
return (
<SearchInput
{...args}
value={value}
onChange={e => setValue(e.target.value)}
onSubmit={e => {
e.preventDefault();
console.log('Submit:', value);
}}
/>
);
},
args: {
placeholder: 'κ²μνμΈμ',
size: 'md',
},
};
μμ
function ControlledSearchInput(
args: typeof SearchInput extends React.ComponentType<infer P> ? P : never
) {
const [value, setValue] = useState('');
return (
<SearchInput
{...args}
value={value}
onChange={e => setValue(e.target.value)}
onSubmit={e => {
e.preventDefault();
console.log('Submit:', value);
}}
/>
);
}
export const Default: Story = {
render: args => <ControlledSearchInput {...args} />,
args: {
placeholder: 'κ²μνμΈμ',
size: 'md',
},
};
λ°μν
'Trouble Shooting & Issues > Linkiving' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
| [WIP]npmμμ pnpmμΌλ‘ λ°κΏ¨λλ storybook actionμ΄ μλ¨Ήνλ€ (0) | 2025.11.03 |
|---|---|
| Button μ»΄ν¬λνΈ λ¦¬ν©ν λ§ νκΈ° (0) | 2025.10.27 |
| @svgr/webpack μ μ©κΈ° (feat. storybook μλ¬) (0) | 2025.10.26 |
| package-lock.jsonμ .gitignore ν΄λ λλ? (0) | 2025.08.12 |
| Linterλ μ μ©μ΄ μλκ³ μμλ€ (0) | 2025.08.12 |
GitHub