UNPKG

openuicomponent

Version:
46 lines (38 loc) 979 B
import React from 'react'; import 'style-loader!css-loader?modules!less-loader!autoprefixer-loader?{browsers:["last 2 version","Firefox 15"]}!./index.less'; class Input extends React.Component { constructor(props){ super(props) this.state = { date: new Date().getTime() } this.focus = this.focus.bind(this) } focus() { this.el.focus(); } render() { return ( <input ref={el=> { this.el = el; }} /> ); } } export default class Son2Farther extends React.Component { componentDidMount() { // Note that when you use ref on a component, it’s a reference to // the component (not the underlying element), so you have access to its methods. this.InputComponent.focus(); } render() { return ( <div> <label>User name:</label> <Input ref={comp => { this.InputComponent = comp; }} /> </div> ) } }