-1

Recently i am working on react.js crud application i like to use react.findDomNode for create record

handleSubmit: function(e) {
        e.preventDefault();
        name = React.findDOMNode(this.refs.name).value.trim();
        email = React.findDOMNode(this.refs.email).value.trim();
        address = React.findDOMNode(this.refs.address).value.trim();
        state = React.findDOMNode(this.refs.state).value.trim();
        zip = React.findDOMNode(this.refs.zip).value.trim();
        city = React.findDOMNode(this.refs.city).value.trim();

but i face following error how can i reslove it i also use

ReactDOM.findDOMNode But still have same error enter image description here

pardeep
  • 359
  • 1
  • 5
  • 7

1 Answers1

1

You should use ReactDOM package.

import ReactDOM from 'react-dom'
const name = React.findDOMNode(this.refs.name).value.trim();

But in your case you can use just refs to get value:

handleSubmit(e) {
    e.preventDefault();
    const name = this.refs.name.value.trim(),
          email = this.refs.email.value.trim(),
          address = this.refs.address.value.trim(),
          state = this.refs.state.value.trim(),
          zip = this.refs.zip.value.trim(),
          city = this.refs.city.value.trim();
}
Ihor Lavs
  • 2,315
  • 2
  • 15
  • 26
  • i also try this , but dont get value its send null value – pardeep May 31 '18 at 10:08
  • Can you show me your JSX with inputs? – Ihor Lavs May 31 '18 at 10:10
  • handleSubmit: function(e) {e.preventDefault();name = this.refs.name.value, email = this.refs.email.value, address = this.refs.address.value, state = this.refs.state.value, if (!name) { return; } // TODO: send request to the server var customer = { name: name, – pardeep May 31 '18 at 10:17