javascript reactjs code example

Example 1: reactjs

npx create-react-app my-app

Example 2: javascript react

class TodoApp extends React.Component {
  constructor(props) {
    super(props);
    this.state = { items: [], text: '' };
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  render() {
    return (
      

TODO

); } handleChange(e) { this.setState({ text: e.target.value }); } handleSubmit(e) { e.preventDefault(); if (this.state.text.length === 0) { return; } const newItem = { text: this.state.text, id: Date.now() }; this.setState(state => ({ items: state.items.concat(newItem), text: '' })); } } class TodoList extends React.Component { render() { return (
    {this.props.items.map(item => (
  • {item.text}
  • ))}
); } } ReactDOM.render( , document.getElementById('todos-example') );

Example 3: react.js

class ShoppingList extends React.Component {
  render() {
    return (
      

Shopping List for {this.props.name}

  • Instagram
  • WhatsApp
  • Oculus
); } } // Example usage:

Tags:

Misc Example