GithubHelp home page GithubHelp logo

jguiraud / exercise1-todo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from reactforbeginners/exercise1-todo

0.0 1.0 0.0 45 KB

Coding your first React.js app

Home Page: http://reactforbeginners.github.io/exercise1-todo/

HTML 100.00%

exercise1-todo's Introduction

Todo app

This exercise will teach you how to create a simple Todo app using React, like this one. You'll learn about components, state, props and also how to change the state based on user input.

To get started, clone this repo. We've linked to the React CDN for you in the HTML file, plus the JSX transformer. Your React components ought to be added in main.js.

Running the app

Simply open the index.html file in the browser to run the app. We're coding everything in that file, so there's no need to run a server.

Break the UI into components

Facebook provides a good tutorial on how to break your UI into components in the official React docs.

It doesn't matter how you do it; in paint, photoshop, on paper or on a napkin. But make sure you've decided on a component structure before you start coding.

image

Building a static version

Head over to the main.js file and start coding your components, withut worrying about user input and state changes. We've added the root component for you, and called React.render(), which renders this component into the DOM in the specified container.

We've also hard coded the todo items into a variable named TODOS, and passed it to the TodoApp component as a props, so that you have some data to populate your static app with.

When you code a dynamic version, you'll discard this props variable and rather place your todo items in a state.

var TODOS = ["buy food", "make food", "eat food"];

var TodoApp = React.createClass({
	render: function(){
		return(<div>{this.props.todos}</div>);
	},
});

React.render(<TodoApp todos={TODOS} />, document.getElementById('content'));

Identifying the state

Now, you'll need to figure out what the app's state will consist of, and where it should live. See the React docs explanation for more info on how to do this. Outtake:

To build your app correctly, you first need to think of the minimal set of mutable state that your app needs. The key here is DRY: Don't Repeat Yourself. Figure out what the absolute minimal representation of the state of your application needs to be and compute everything else you need on-demand.

Fetching user input

We recommend that you use controlled components when working with the input field, and setting the state with the onChange event.

Alternatively you can use refs and findDOMNode. However, this techinque will be covered in exercise 2, so use controlled components in order to learn as much as possible.

Stretch goals:

If you finish up before the deadline, use the remaining time to add extra features to the app.

  • Multiple lists
    The user clicks New list, and a new list appears on the page, which he/her can add and delete items on.

  • Edit existing items
    The user clicks on an item, enabling it to be modified.

exercise1-todo's People

Contributors

johnsmith78 avatar perborgen 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.