rawbee
rawbee

Reputation: 3008

How do I clear an uncontrolled textarea in react.js?

I can get the value just fine using:

this.refs.myTextArea.getDOMNode().value

Trying to set that does nothing.

Upvotes: 3

Views: 4147

Answers (3)

Vincent Taing
Vincent Taing

Reputation: 3334

In even newer version of React ( > v15 ), you don't need findDOMNode(), this.refs.myTextArea.value ='' is enough

Upvotes: 6

goofballLogic
goofballLogic

Reputation: 40459

this.refs.myTextArea.getDOMNode().value = "";

Upvotes: 6

Chenglu
Chenglu

Reputation: 1997

Is the value of your textarea being bind to a state of your component?

If yes then you can't set value like this, what you should do is call setState to change it.

Upvotes: 0

Related Questions