0

I have a textarea

<textarea ref="newText" defaultValue={this.props.children}></textarea>

I need to fetch its value,I tried like this.

this.props.update(this.refs.newText.value,this.props.index);

I also used text instead of value but still it returns undefined.

this.refs.newText.value

2 Answers 2

1

Try updating your react-dom libraries. ref help you to imperatively modify a child without the need to use props.get the latest from react docs

src="https://unpkg.com/react@15/dist/react.js"> src="https://unpkg.com/react-dom@15/dist/react-dom.js">

Check out Refs & the DOM

Sign up to request clarification or add additional context in comments.

Comments

0

It's hard to debug without the full source code of your component. I've prepared a codepen which shows two ways of accessing the value entered in the <textarea/> element: http://codepen.io/PiotrBerebecki/pen/amJAqb

Have a look also at the React Forms docs: https://facebook.github.io/react/docs/forms.html#controlled-components

const TextArea = React.createClass ({ 
  getInitialState: function() {
    return {
      userInputValue: '',
      userInputRefs: ''
    };
  },

  handleChange: function(event) {
    this.setState({
      userInputValue: event.target.value
    });
    this.setState({
      userInputRefs: this.refs.userData.value
    });   
  },

  render: function() {
    return (
      <div>
        <textarea ref="userData"
                  type="text"
                  onChange={this.handleChange}
                  value={this.state.userInputValue} />
        <h3>User input value:</h3>
        <p>{this.state.userInputValue}</p>
        <h3>User input refs:</h3>
        <p>{this.state.userInputRefs}</p>
      </div>
    );
  }
})


ReactDOM.render(
  <TextArea />,
  document.getElementById('app')
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.