C
C
cvbcvb cvbcvbcvbcvb2016-01-04 02:02:17
JavaScript
cvbcvb cvbcvbcvbcvb, 2016-01-04 02:02:17

Why is ReactJS not rendering?

Began to learn React
Doesn't render for some reason...
I don't see an error
or in general... what is the right way of thinking?

var TextInput = React.createClass({
  getInitialState: function(){
    text: ''
  },
  handleVal: function(e){
    this.setState({text: e.target.value})
  },
  render: function(){
    return (
      <input value={this.state.text} onChange={this.handleVal} required />
    )
  }
});



var RegForm = React.createClass({
  newUser: function(e) {
    $.ajax({
      url: 'ajax/path',
      method: 'post',
      dataType: 'json',
      data: {
        login: this.state.login,
        email: this.state.email,
        pass: this.state.pass,
        rep_pass: this.state.rep_pass
      },
      success: function(data) {
        this.setState({
          login: '',
          email: '',
          pass: '',
          rep_pass: ''
        });
      }.bind(this)
    });
  },
  render: function() {
    return (
      <form className="regForm">
        <TextInput
        name="login"
        id="login"
        type="text"
        placeholder="Login"
        minLength="3" />

        <TextInput
        name="email"
        id="email"
        type="email"
        placeholder="Email"
        className="validate" />

        <TextInput
        name="pass"
        id="pass"
        type="password"
        placeholder="Password" />

        <TextInput
        name="rep_pass"
        id="rep_pass"
        type="password"
        placeholder="Repeat password" />

        <input type="submit" className="waves-effect waves-light btn green accent-4" value="Registration" />

      </form>
    );
  }	
});

ReactDOM.render(
  <RegForm />,
  document.getElementById('reg_form')
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andreyqin, 2016-01-04
@andreyqin

At a minimum, getInitialState must return an object. Check if React and ReactDOM are properly connected to the page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question