250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 최솟갑 구하기
- 구름톤
- 중첩 점
- Jest uuid syntax
- 테스트 Date
- Leetcode #javascript #알고리즘 #Algorithms #js
- 날짜 테스트
- JavaScript
- 테이블 해시 함수
- mock date
- nextjs-performance
- 호텔 대실
- Hermes Engine
- 헤르메스 엔진
- mutationobserver
- 통신망분석
- 구름톤챌린지
- Google 애널리틱스
- 자바스크립트
- nextjs
- 리액트네이티브 엔진
- 과제 진행하기
- ResizeObserver
- create-next-app
- 리액트네이티브
- 귤 고르기
- 구름톤 챌린지
- jest
- 프로그래머스
- 연결 요소 제거하기
Archives
- Today
- Total
나만보는개발공부블로그
[React] React.cloneElement 본문
React.cloneElement()
- 지정한 Element를 복사해 반환한다. 추가적으로 children과 props를 같이 넘겨줄 수 있어서 필요시에 부모에서의 props를 자식에게 props를 전달해야하는 경우 사용할 수 있다.
React.cloneElement(
element,
[props],
[...children]
)
사용 예시
- Parent.tsx
{React.Children.map(props.children, (child) => {
if (child) {
return React.cloneElement(child as ReactElement, {
onDragHandle: provided.dragHandleProps ?? null
});
} else {
return child;
}
})}
- Drag.tsx
<Parent onDragEnd={handleDragAndDrop} disabled={!enableDagAndDrop}>
<Children>
...
</Children>
</Parent>
-Children.tsx
const Children:FC<ChildrenProps> = ({children:React.ReactNode,onDragHandle:SomeProps}) => {
return <SomeComponent {...onDragHandle} />
}
'Web Development > Front' 카테고리의 다른 글
Storybook 적용 (0) | 2022.04.27 |
---|---|
[React]ref 와 forwardRef (0) | 2021.12.15 |
[State]상태관리 (0) | 2021.03.30 |
[Angular] Data Binding & Change Detection (0) | 2021.03.12 |
[Angular] Angular Template Syntax (0) | 2021.03.12 |