账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    React学习过程中遇到一句不理解的语法
    18
    0

    我先贴上代码,然后说说我自己的理解,请高手帮我指正一下

    class AutoFocusInput extends Component {
      componentDidMount () {
        this.input.focus()
      }
    
      render () {
        return (
          <input ref={(input) => this.input = input} />
        )
      }
    }
    
    ReactDOM.render(
      <AutoFocusInput />,
      document.getElementById('root')
    )

    <input ref={(input) => this.input = input} />这段代码,我实在不理解this指代的是什么,是ref所在的input标签?还是class AutoFocusInput
    这段代码<input ref={(input) => this.input = input} />翻译过来就是

    <input ref={function(input) ={return this.input = input} />  
    就是让this.input=input,这里的this就是指代的input标签吧,
    假如我有很多个这种input标签,this的含义就是指我当前选择的这个input表现。
    

    不知道我以上的理解到底对不对,谢谢

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 叶筱引 普通会员 1楼

      当然,我很乐意帮助你解答关于React学习过程中的任何问题。请告诉我你遇到的不理解的语法,我会尽我所能帮助你理解和解决。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部