V
V
Valen962018-03-01 06:48:43
JavaScript
Valen96, 2018-03-01 06:48:43

How to fix React code and use babel?

Tell me, I'm going through react lessons and this code does not work, the error, as I understand it, is in setting up webpack or babel , here's the code

import React , { Component } from 'react';

class SearchBar extends Component {
constructor(props) {
  super(props);

  this.state={  term: ' ' };
}

  render() {
    return {
      <div>
  <input onChange={event => this.setState( { term:event.target.value} ) }/>;
val of inp:
</div>
};
}
}
export default SearchBar;

Writes Unexpected token in the compiler, and if you put this code in https://babeljs.io/ it also shows an error!
Tell me how to solve
?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-03-01
@Valen96

import React, { Component } from 'react';

class SearchBar extends Component {
  constructor(props) {
    super(props);

    this.state = { term: ' ' };
  }

  render() {
    return ( // в круглых скобках возвращаем, если более 1й строки
      <div>
        <input onChange={event => this.setState({ term: event.target.value })} />;
      </div>
    )
  }
}
export default SearchBar;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question