728x90
App
import ChildComponent from "./components/ChildComponent"
export default function App(){
return(
<>
<h1>App</h1>
<ChildComponent ></ChildComponent>
</>
)
}
ChildComponent
import SubChildComponent from "./SubChildComponent"
export default function ChildComponent(props){ //props빠짐
function handelEvent(v){
console.log("handelEvent: "+ v)
}
return(
<>
<h2>ChildComponent</h2>
<SubChildComponent onSelect={(e) => handelEvent(e)}>ChildComponent에서</SubChildComponent>
</>
)
}
SubChildComponent
export default function SubChildComponent(props){ //{children, onSelect}대신
console.log(props)
const{onSelect} = props; //이벤트 받기
return(
<>
<h3>SubChildComponent</h3>
<button onClick={onSelect}>call</button>
</>
)
}
'단순 코드 기록 > React' 카테고리의 다른 글
React_실시간 랜더링 (0) | 2024.03.14 |
---|---|
React_eventPreventDefault()와 StopPropagation() (0) | 2024.03.14 |
React_버튼 이벤트 처리 (0) | 2024.03.14 |
React_자식에서 데이터 변경 (0) | 2024.03.13 |
React_스프레드 함수_이중 자식창 (0) | 2024.03.13 |