Using React.findDOMNode in TypeScript

后端 未结 5 573
难免孤独
难免孤独 2021-02-04 16:24

I\'m following the React Tutorial and got stuck on how to use React.findDOMNode.

Here is my code:

export class CommentForm extends React.Com         


        
5条回答
  •  面向向阳花
    2021-02-04 17:06

    EDIT: nlaq provided the answer to my question, however I think the following can be useful for readers, so I will leave this answer up.

    After reading Forms | React article, I was able to acquire the value by handling the onChange event:

    handleChange(e) {
        e.preventDefault();
        console.log(e.target.value); // e.target.value gives the value in the input box
    }
    
    render() {
        return 
    this.handleSubmit(e) }> this.handleChange(e) } placeholder="Your name" />
    ; }

    I'm still puzzled why the tutorial showed the use of findDOMNode. Perhaps the tutorial is showing an old way? I'm still new to React, so if there is a more intuitive way please let me know.

    For a full example, this SO answer helped me out.

提交回复
热议问题