test_component.jsx 587 B

123456789101112131415161718192021222324252627282930313233
  1. import React from 'react';
  2. class TestComponent extends React.Component {
  3. constructor(props) {
  4. super(props);
  5. this.state = {text: ''};
  6. this.onChange = this.onChange.bind(this);
  7. }
  8. onChange(e) {
  9. this.updateText(e.target.value);
  10. }
  11. updateText = text => {
  12. this.setState({text: text});
  13. };
  14. render() {
  15. return (
  16. <div>
  17. <div>
  18. <h1>React lives!</h1>
  19. </div>
  20. Is React working? Test here: {this.state.text}
  21. <hr />
  22. <input onChange={this.onChange} />
  23. </div>
  24. );
  25. }
  26. }
  27. export default TestComponent;