React stateless component this.refs..value?

后端 未结 7 1726
故里飘歌
故里飘歌 2020-12-03 01:09

I don\'t know if I\'m doing this correctly... If I want to get value from an input I use this.refs.whatever.value.trim() but if that input is a stateless function component

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 01:37

    Nowadays, you would want to avoid to use the ref attribute to get values from input fields. Instead you should use React's local state. The ref attribute is reserved for only a few use cases:

    • Managing focus, text selection, or media playback
    • Integrating with third-party DOM libraries
    • Triggering imperative animations

提交回复
热议问题