import React , { Component } from "react" ; type Props = { onParentRef : ( ref : React . RefObject < Child > ) => React . RefObject < Child > ; } ; interface ParentType { } class Child extends Component < Partial < Props > > { state : { age : number ; } ; constructor ( props ) { super ( props ) ; if ( props . onParentRef ) { props . onParentRef ( this as any ) ; } this . state = { age : 26 , } ; this . sangheonZZang = this . sangheonZZang . bind ( this ) ; } sangheonZZang ( ) { console . log ( `이름 김상헌 나이는 ${ this . state . age }살 입니다.` ) ; } render ( ) { return ( < div > < h2 > 여기는 Child 컴포넌트 . < /h2> < /div>); } } class Parent extends Component { childComponent : any ; constructor ( props ) { super ( props ) ; this . childComponent = React . createRef ( ) ; this . callChildMethod = this . callChildMethod . bind ( this ) ; } description memberof callChildMethod ( ) { this . childComponent . sangheonZZang ( ) ; console . log ( this . childComponent . state . age ) ; } render ( ) { return ( < div > < h1 > 여기는 부모 컴포넌트 . < /h1> < Child onParentRef = { ( ref ) => ( this . childComponent = ref ) } /> < button onClick = { this . callChildMethod } > 블라블라 < /button> < /div>); } } export default Parent ;