2

When I test the following code I receive a console error that newText is undefined, am I declaring the val var correctly or am I missing something?

val = ReactDOM.findDOMNode(this.refs[newText]);

renderForm: function() {
        return (
            <div className="note">
                <textarea ref="newText" defaultValue={this.props.children} className="form-control"></textarea>
                <button onClick={this.save} className="btn btn-success btn-sm glyphicon glyphicon-floppy-disk"></button>
            </div>
        )
    },
1
  • val = ReactDOM.findDOMNode(this.refs[newText]); is called in another function? Commented Apr 14, 2016 at 12:54

3 Answers 3

2

newText here needs to be either a string ("newText") or should use dot notation instead. Using just newText means you're trying to read the value of a variable with that name (which will return undefined).

Change:

this.refs[newText]

To:

this.refs["newText"]

Or:

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

Comments

1

I know it's very late to answer this but I came across the same problem.

I added and update the following sources: src= "https://unpkg.com/react@15/dist/react.js"> src="https://unpkg.com/react-dom@15/dist/react-dom.js">

It worked for me.

Hope you already found a solution for this. Cheers!

1 Comment

0

use this.refs.newText rather than this.refs[newText].

1 Comment

I did try this but receive the following "TODO: Save not Value[object HTMLTextAreaElement]" I then also tried this.refs.newText.value but still no joy

Your Answer

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