GithubHelp home page GithubHelp logo

john11d-payu-gpo / 01ieti-reactintro Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ieti-eci/1.1-react-intro

0.0 1.0 0.0 152 KB

Introduction to React

HTML 13.23% CSS 7.22% JavaScript 79.55%

01ieti-reactintro's Introduction

React JS Intro

Introduction to ReactJS.

Part 1: Create a basic React Application and understand React basics

  1. Create a react App and test that it works:
  npx create-react-app todo-app
  cd my-app
  npm start
  1. Open the index.html file and replace the title tag from React App to TODO App.

  2. Open the App.js file and change App-title to TODO React App (verify if the changes are reflected inmediately on your browser after you save without re-running your server).

  3. Go to Codeacademy, register and do the first two modules (JSX and React Components) of the following course: https://www.codecademy.com/learn/react-101

Part 2: Create React Components for the TODO App

  1. Create a new JavaScript file called Todo.js
import React from 'react';

export class Todo extends React.Component {

    constructor(props) {
        super(props);
    }   

    render() {
        return (  
          //Add your code here to represent a TODO
        );
    }

}
  1. Read about React Components & Props: https://reactjs.org/docs/components-and-props.html

  2. Once your understand these concepts, then add the HTML code to display the TODO information. You will access the TODO data by using the react props text , priority and dueDate as the following example (notice the curly braces inside the HTML used to evaluate the JavaScript expression)

<h2>{this.props.text}  ... </h2> 
//Do not forget to add the other properties of your TODO!
  1. Create another React Component called TodoList. This Component should render a list of Todo components. You can access the todo list by using the props: this.props.todoList. Start by importing the Todo component and the React module:
import React from 'react';
import {Todo} from './Todo'

hint: You should use the map function to dynamically create your list inside the render method as the following example: https://codepen.io/gaearon/pen/jrXYRR?editors=0011

React Documentation: https://reactjs.org/docs/lists-and-keys.html

  1. Import your TodoList component into the App.js file and then add the tag to your code so it loads the Todo list. You can use the following code to create some sample data:
render() {
      const todos = [{text:"Learn React", priority:5, dueDate: new Date() },
          {text:"Learn about APIs", priority:4, dueDate: new Date(2018,8,30) },
          {text:"write TODO App", priority:3, dueDate: new Date(2018,9,30) }];
 
 ...
 
 <TodoList todoList={todos}/>
  1. Run your application and verify that it works as expected:
  npm start 

Part 3: Interacting with React Components

  1. Go back the Codeacademy website and do the the last module (Components Interacting) of the Learn ReactJS: Part I course.

  2. Use the following code code(taken from the React website) as a refence to create a form that captures the Todo data(text, priority and date), and adds the new objetc to the list.

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 (
      <div>
        <h3>TODO</h3>
        <TodoList items={this.state.items} />
        <form onSubmit={this.handleSubmit}>
          <label htmlFor="new-todo">
            What needs to be done?
          </label>
          <input
            id="new-todo"
            onChange={this.handleChange}
            value={this.state.text}
          />
          <button>
            Add #{this.state.items.length + 1}
          </button>
        </form>
      </div>
    );
  }

  handleChange(e) {
    this.setState({ text: e.target.value });
  }

  handleSubmit(e) {
    e.preventDefault();
    if (!this.state.text.length) {
      return;
    }
    const newItem = {
      text: this.state.text,
      id: Date.now()
    };
    this.setState(prevState => ({
      items: prevState.items.concat(newItem),
      text: ''
    }));
  }
}

01ieti-reactintro's People

Contributors

sancarbar avatar john11d-payu-gpo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.