import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/app';
const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
import React from 'react';
class App extends React.Component {
render(){
return (
<div>
<Header/>
<Content/>
</div>
);
}
}
export default App;
import React from 'react';
class App extends React.Component {
render(){
return (
<div>
<Header/>
<Content/>
</div>
);
}
}
class Header extends React.Component {
render(){
return (
<h1>Header</h1>
);
}
}
class Content extends React.Component {
render(){
return (
<div>
<h2>Content</h2>
<p> Hey! </p>
</div>
);
}
}
export default App;
import React from 'react';
class Header extends React.Component {
render(){
return (
<h1>Header</h1>
);
}
}
export default Header;
import React from 'react';
class Content extends React.Component {
render(){
return (
<div>
<h2>Content</h2>
<p> Hey! </p>
</div>
);
}
}
export default Content;
import React from 'react';
import Header from './header';
import Content from './content';
class App extends React.Component {
render(){
return (
<div>
<Header/>
<Content/>
</div>
);
}
}
export default App;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script src="bundle.js"></script>
</body>
</html>
import React from 'react';
class Header extends React.Component {
render(){
return (
<h1>{ this.props.title }</h1>
);
}
}
export default Header;
import React from 'react';
class Content extends React.Component {
render(){
return (
<div>
<h2>{ this.props.title }</h2>
<p> { this.props.body } </p>
</div>
);
}
}
export default Content;
import React from 'react';
import Header from './header';
import Content from './content';
class App extends React.Component {
render(){
return (
<div>
<Header title={ this.props.headerTitle }/>
<Content title={ this.props.contentTitle }
body={ this.props.contentBody }/>
</div>
);
}
}
export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/app';
const rootElement = document.getElementById('root');
ReactDOM.render(<App headerTitle = "Welcome!"
contentTitle = "Developer,"
contentBody = "Welcome to Web"/>, rootElement);
import React from 'react';
import ReactDOM from 'react-dom';
import Header from './header';
import Content from './content';
class App extends React.Component {
render(){
return (
<div>
<Header title={ this.props.headerTitle }/>
<Content title={ this.props.contentTitle }
body={ this.props.contentBody }/>
</div>
);
}
}
App.defaultProps = {
headerTitle: 'Default header',
contentTitle: 'Default contentTitle',
contentBody: 'Default contentBody'
};
export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/app';
const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
import React from 'react';
class Content extends React.Component {
render(){
return (
<div>
<h2>{ this.props.title }</h2>
<p> { this.props.body } </p>
</div>
);
}
}
Content.propTypes = {
title: React.PropTypes.string,
body: React.PropTypes.string.isRequired
};
export default Content;
import React from 'react';
import ReactDOM from 'react-dom';
import Header from './header';
import Content from './content';
class App extends React.Component {
render(){
return (
<div>
<Header title={ this.props.headerTitle }/>
<Content title={ this.props.contentTitle }
body={ this.props.contentBody }/>
</div>
);
}
}
App.defaultProps = {
headerTitle: 'Default header',
contentTitle: 5,
contentBody: undefined
};
export default App;
import React from 'react';
class StateExample extends React.Component {
constructor(props) {
super(props);
this.state = {
header: "Header Initial state",
content: "Content Initial State"
};
}
updateHeader(text){
this.setState({
header: "Header has changed"
});
}
render() {
return (
<div>
<h1>{this.state.header}</h1>
<h2>{this.state.content}</h2>
<button onClick={this.updateHeader.bind(this)}>Update</button>
</div>
);
}
}
export default StateExample;
import React from 'react';
import ReactDOM from 'react-dom';
class RandomNumber extends React.Component {
updateNumber(){
let value = Math.round(Math.random()*100);
this.props.onUpdate(value);
}
constructor(props){
super(props);
this.updateNumber = this.updateNumber.bind(this);
}
render(){
return (
<div>
<h1>RANDOM NUMBER: { this.props.number }</h1>
<button onClick={this.updateNumber}>Randomize</button>
</div>
);
}
}
export default RandomNumber;
import React from 'react';
import ReactDOM from 'react-dom';
import Header from './header';
import Content from './content';
import RandomNumber from './randomNumber';
class App extends React.Component {
constructor(props){
super(props);
this.state = {
value: Math.round(Math.random()*100)
};
this.updateValue = this.updateValue.bind(this);
}
updateValue(randomValue){
this.setState({
value: randomValue
});
}
render(){
return (
<div>
<Header title={ this.props.headerTitle }/>
<Content title={ this.props.contentTitle }
body={ this.props.contentBody }/>
<RandomNumber number={this.state.value}
onUpdate={this.updateValue} />
</div>
);
}
}
App.defaultProps = {
headerTitle: 'Default header',
contentTitle: 'Default contentTitle',
contentBody: 'Default contentBody'
};
export default App;
import React from 'react';
class App extends React.Component {
render(){
return (
<Contacts/>
);
}
}
class Contacts extends React.Component {
render(){
return(
<div>
<h1>Contacts</h1>
<ul>
<li>Abet 010-0000-0001</li>
<li>Betty 010-0000-0002</li>
<li>Chalie 010-0000-0003</li>
<li>David 010-0000-0003</li>
</ul>
</div>
);
}
}
export default App;
class ContactInfo extends React.Component {
render() {
return(
<li>{this.props.name} {this.props.phone}</li>
);
}
}
render(){
return(
<div>
<h1>Contacts</h1>
<ul>
<ContactInfo name="Abet" phone="010-0000-0001"/>
<ContactInfo name="Betty" phone="010-0000-0002"/>
<ContactInfo name="Charlie" phone="010-0000-0003"/>
<ContactInfo name="David" phone="010-0000-0004"/>
</ul>
</div>
);
}
constructor(props) {
super(props);
this.state = {
contactData: [
{name: "Abet", phone: "010-0000-0001"},
{name: "Betty", phone: "010-0000-0002"},
{name: "Charlie", phone: "010-0000-0003"},
{name: "David", phone: "010-0000-0004"}
]
};
}
render(){
return(
<div>
<h1>Contacts</h1>
<ul>
{this.state.contactData.map((contact, i) => {
return (<ContactInfo name={contact.name}
phone={contact.phone}
key={i}
/>
);
})}
</ul>
</div>
);
}
import React from 'react';
class App extends React.Component {
render(){
return (
<Contacts/>
);
}
}
class Contacts extends React.Component {
constructor(props) {
super(props);
this.state = {
contactData: [
{name: "Abet", phone: "010-0000-0001"},
{name: "Betty", phone: "010-0000-0002"},
{name: "Charlie", phone: "010-0000-0003"},
{name: "David", phone: "010-0000-0004"}
]
};
}
render(){
return(
<div>
<h1>Contacts</h1>
<ul>
{this.state.contactData.map((contact, i) => {
return (<ContactInfo name={contact.name}
phone={contact.phone}
key={i}/>);
})}
</ul>
</div>
);
}
}
class ContactInfo extends React.Component {
render() {
return(
<li>{this.props.name} {this.props.phone}</li>
);
}
}
export default App;
constructor(props){
super(props);
console.log("constructor");
}
componentWillMount(){
console.log("componentWillMount");
}
componentDidMount() {
console.log("componentDidMount");
}
componentWillReceiveProps(nextProps){
console.log("componentWillReceiveProps: " + JSON.stringfy(nextProps));
}
shouldComponentUpdate(nextProps, nextState){
console.log("shouldComponentUpdate: " + JSON.stringfy(nextProps) + " " + JSON.stringfy(nextState));
return true;
}
componetWillUpdate(nextProps, nextState){
console.log("componentWillUpdate: " + JSON.stringfy(nextProps) + " " + JSON.stringfy(nextState));
}
componentDidUpdate(prevProps, prevState){
console.log("componentDidUpdate: " + JSON.stringfy(prevProps) + " " + JSON.stringfy(prevState));
}
componentWillUnmount(){
console.log("componentWillUnmount");
}