Skip to content

Commit b495aa7

Browse files
committed
Add README file, comments in index.html and updated PPTX.
1 parent f2d85f5 commit b495aa7

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

Introducing React.pptx

884 KB
Binary file not shown.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Recat
2+
3+
## What is Recat?
4+
React is a extremely simple web page to load cat pictures from a API called [The Cat Api](http://thecatapi.com/).
5+
6+
The purpose of this is to show how React can be used to load data through Ajax and display it with a bit of user interaction.
7+
8+
## Installation
9+
Just do a `git clone` to get a local copy:
10+
11+
git clone https://github.com/grenoult/recat.git
12+
13+
Then simply open `index.html` with your browser to play around.
14+
15+
## Author
16+
Guillaume Renoult, November 2016.
17+
18+
:cat:

index.html

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<head>
44
<meta charset="utf-8">
55
<title>React Tutorial with cats</title>
6-
<!-- Not present in the tutorial. Just for basic styling. -->
76
<link rel="stylesheet" href="css/bootstrap.min.css" />
87
<script src="scripts/react.js"></script>
98
<script src="scripts/react-dom.js"></script>
@@ -21,10 +20,17 @@
2120
class CatApp extends React.Component {
2221
constructor(props) {
2322
super(props);
24-
this.handleSubmit = this.handleSubmit.bind(this);
23+
this.handleSubmit = this.handleSubmit.bind(this); // Add context
24+
this.handleRemove = this.handleRemove.bind(this);
2525
this.state = {items: [], text: ''};
2626
}
2727

28+
/**
29+
* Handle picture removal.
30+
*
31+
* Passed to CatList component through props,
32+
* so called in CatList but executed in this component.
33+
*/
2834
handleRemove(id) {
2935
var items = this.state.items;
3036

@@ -48,7 +54,7 @@
4854
return (
4955
<div className="container">
5056
<h1>Cat + React = Recat</h1>
51-
<CatList items={this.state.items} handleRemove={this.handleRemove.bind(this)} />
57+
<CatList items={this.state.items} handleRemove={this.handleRemove} />
5258
<div className="row">
5359
<div className="cold-md-12 text-center">
5460
<form onSubmit={this.handleSubmit}>
@@ -60,6 +66,15 @@ <h1>Cat + React = Recat</h1>
6066
);
6167
}
6268

69+
/**
70+
* Handle adding a new picture.
71+
*
72+
* This will:
73+
* - Add a new record in the list of items
74+
* - Call render() on this component because we update the state
75+
* - Call render() on CatList component because we render its owner
76+
* - React with JSX is smart to know that only one (new) component needs to be rendered in the DOM
77+
*/
6378
handleSubmit(e) {
6479
e.preventDefault();
6580

0 commit comments

Comments
 (0)