关于一段react代码片段 有点疑问

import React, { Component, PropTypes } from 'react';
import { browserHistory } from 'react-router';

class SearchGithub extends Component {
    static PropTypes = {
        history: PropTypes.object.isRequired
    }
    getRef(ref){
        this.usernameRef = ref;
        console.log(ref);
    }
    handleSubmit(event){
        const username = this.usernameRef.value;
        this.usernameRef.value = '';

        const path = `/profile/${username}`;
        browserHistory.push(path)

    }
    render(){
        return (
            <div className="col-sm-12">
                <form onSubmit={() => this.handleSubmit()}>
                    <div className="form-group col-sm-7">
                        <input type="text" className="form-control" ref={(ref) => this.getRef(ref)} />
                    </div>
                    <div className="form-group col-sm-5">
                        <button type="submit" className="btn btn-block btn-primary">搜索 Github</button>
                    </div>
                </form>
            </div>
        )
    }
}

export default SearchGithub;

这是一个搜索组件,上面的:

getRef(ref){
        this.usernameRef = ref;
        console.log(ref);
    }

函数与下面的

<input type="text" className="form-control" ref={(ref) => this.getRef(ref)} />
这是什么意思啊 大家有知道的或者这么用的吗

阅读 1.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题