fcc-react-intro

In this example below you will see how to do a fcc-react-intro with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by belcurv, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright belcurv ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>fcc-react-intro</title>
  
  
  
  
  
</head>

<body>

  <div id="container"></div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.development.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.development.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/belcurv/fcc-react-intro-YLZMBE */
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

// https://www.youtube.com/watch?v=QqLkkBKVDyM

var ListItem = function ListItem(props) {
  return React.createElement(
    "li",
    { onClick: props.onClick },
    props.item
  );
};

var AddItemForm = function AddItemForm(props) {
  return React.createElement(
    "form",
    { onSubmit: props.onSubmit },
    React.createElement("input", { type: "text", id: "itemInput", placeholder: "Add item" })
  );
};

var ShoppingList = function (_React$Component) {
  _inherits(ShoppingList, _React$Component);

  function ShoppingList() {
    _classCallCheck(this, ShoppingList);

    var _this = _possibleConstructorReturn(this, (ShoppingList.__proto__ || Object.getPrototypeOf(ShoppingList)).call(this));

    _this.state = {
      list: ['unicycle', 'juggling clubs', 'stilts']
    };
    return _this;
  }

  _createClass(ShoppingList, [{
    key: "handleClicked",
    value: function handleClicked(index) {
      var copyList = this.state.list.slice();
      copyList.splice(index, 1);
      this.setState({ list: copyList });
    }
  }, {
    key: "handleAddItem",
    value: function handleAddItem(e) {
      var copyList = this.state.list.slice();
      copyList.push(e.target[0].value);
      this.setState({ list: copyList });
      e.target[0].value = '';
      e.preventDefault();
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var listItems = this.state.list.map(function (item, i) {
        return React.createElement(ListItem, {
          key: item,
          item: item,
          onClick: function onClick() {
            return _this2.handleClicked(i);
          }
        });
      });

      return React.createElement(
        "div",
        { className: "shopping-list" },
        React.createElement(
          "h1",
          null,
          "Shopping List for ",
          this.props.name
        ),
        React.createElement(AddItemForm, { onSubmit: function onSubmit(e) {
            return _this2.handleAddItem(e);
          } }),
        React.createElement(
          "ul",
          null,
          listItems
        )
      );
    }
  }]);

  return ShoppingList;
}(React.Component);

ReactDOM.render(React.createElement(ShoppingList, { name: "Jay" }), document.getElementById("container"));

Comments