react to obtain several forms of ref
Defined constructor (The props) { Super (The props); the this .STATE = {}; the this .textInput = React.createRef (); // look here } bind the render () { return ( <div> <P> original test event the difference between the synthetic event </ P> <div> <Button REF = { the this .textInput seen here} // = className "Button" the onClick = { the this .onReactClick}> click </ Button> </ div> </ div > ); } using the this .textInput.current.addEventListener ( 'the Click', the this .onDomClick,false);
Binding the render () { return ( <div> <P> test event difference between native and synthetic event </ P> <div> <REF = Button "the textInput" // see where = className "Button" the onClick = { the this . onReactClick}> click </ Button> </ div> </ div> ); } using the this .refs.textInput.addEventListener ( 'the click', the this .onDomClick, to false );
Binding the render () { return ( <div> <P> original test event difference synthetic event </ P> <div> <REF = Button "the textInput" className = "Button" the onClick = { the this .onReactClick}> Click </ Button> </ div> </ div> ); } use const parentDom = ReactDOM.findDOMNode ( the this .refs.textInput); // see where parentDom.addEventListener ( 'the Click', the this .onDomClick, to false );
ReactDOM.findDOMNode (this) // can get directly to the root of the current assembly