Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

컴포넌트의 props drilling depth는 어디까지 허용하는가? #1

Open
BoBeenLee opened this issue Aug 4, 2022 · 2 comments

Comments

@BoBeenLee
Copy link
Owner

BoBeenLee commented Aug 4, 2022

개발자 기준에 따라 다르겠지만 내 기준은 depth 2까지는 허용가능한 범위라 생각한다.

  • ex) todo리스트 전달, TodoPage -> TodoSection -> Todos

Solution 1

만일 depth 2 초과되었을 경우엔 컴포넌트 전달방식(children, label, caption)으로 처리하여 depth를 줄여 리팩토링한다.

<TodoSection>
   <Todos todos={todos} />
</TodoSection>

props 속성으로 컴포넌트를 전달한다.

<Input label={<Label />} value={...} />

이와 같이 했을 경우 페이지 내에서 todos를 전달할 수 있어 depth가 1이 될 수 있다.

@BoBeenLee
Copy link
Owner Author

Solution 2

  • Compound Component
<TodoSection>
   <Todo.Root>
       {todos.map(todo => {
            return <Todo.Item key={todo.id}>{todo.name}<Todo.Item>
       }}
   <Todo.Root>
</TodoSection>

@BoBeenLee
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant