sugar-for-pirate-king / react-waifu-list

Simple react app to listing waifus including simple even handler.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React waifu list

Simple react app to listing waifus with simple handler.

// app.js

import React from "react";
import "./App.css";

class Waifu extends React.Component {
  render() {
    return <span>Waifu {this.props.name}</span>;
  }
}

class Waifus extends React.Component {
  constructor(props) {
    super(props);
    const waifus = [
      { id: 1, name: "Emilia" },
      { id: 2, name: "Rem" },
      { id: 3, name: "Kokom1" }
    ];
    this.state = {
      waifus
    };
    this.removeWaifu = this.removeWaifu.bind(this);
  }

  removeWaifu(id) {
    let updatedWaifus = [];
    this.state.waifus.forEach(waifu => {
      if (waifu.id !== id) {
        updatedWaifus.push(waifu);
      }
    });
    this.setState({ waifus: updatedWaifus });
  }

  render() {
    return (
      <div>
        <h4>List of waifus</h4>
        {this.state.waifus.map(waifu => (
          <li key={waifu.id}>
            <Waifu name={waifu.name} />
            <button onClick={e => this.removeWaifu(waifu.id)}>Remove</button>
          </li>
        ))}
      </div>
    );
  }
}

function App() {
  return (
    <div className="App">
      <Waifus />
    </div>
  );
}

export default App;

About

Simple react app to listing waifus including simple even handler.


Languages

Language:JavaScript 76.3%Language:HTML 19.3%Language:CSS 4.4%