-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.jsx
97 lines (85 loc) · 2.54 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React from 'react';
import { ReactTinyDOM } from './renderer/tiny-dom';
function Card(props) {
return (
<div className="card" style={{ padding: '1rem', margin: '0 auto', width: '20rem' }}>
<img
className="card-img-top"
src="https://s3-us-west-2.amazonaws.com/cosmicjs/9c2d95d0-27b0-11e7-b6ae-8108cf4caa96-react.svg"
alt="React tiny DOM"
style={{ height: '10rem' }}
/>
<div className="card-body">
<h4 className="card-title">{props.title}</h4>
<p className="card-text">{props.children}</p>
<button onClick={props.onClick} className="btn btn-outline-primary">
{props.buttonText}
</button>
</div>
</div>
);
}
class HelloWorld extends React.Component {
state = {
counter: 0,
};
handleClick = () => {
console.clear(); // Clear the console to show only new method calls
this.setState({
counter: this.state.counter + 1,
});
}
render() {
const isEven = this.state.counter % 2 === 0;
const styles = {
color: isEven ? '#673AB7' : '#F44336',
};
return (
<div className="container text-center pt-5" style={styles}>
<Card title="React tiny DOM" buttonText="Counter" onClick={this.handleClick}>
<p>A minimal implementation of react-dom using react-reconciler APIs</p>
<p>Counter: {this.state.counter}</p>
<p>
<button disabled={isEven} className="btn btn-light">
I'm disabled based on the state.
</button>
</p>
</Card>
</div>
);
}
}
ReactTinyDOM.render(<HelloWorld />, document.querySelector('.root'));
/**
* A more basic application to see and understand better the Renderer method calls in the console.
*/
// class HelloWorld extends React.Component {
// constructor() {
// super();
// this.state = {
// value: 0,
// };
// this.handleClick = this.handleClick.bind(this);
// }
// handleClick() {
// this.setState({
// value: this.state.value + 1,
// });
// }
// render() {
// const styles = {
// backgroundColor: this.state.value % 2 === 0 ? 'red' : 'green',
// };
// return (
// <div className="container text-center pt-5" tabIndex={this.state.value} style={styles}>
// <h1>react-tiny-dom</h1>
// <p>Counter: {this.state.value}</p>
// <p>
// <button onClick={this.handleClick} className="btn btn-outline-primary">
// Counter
// </button>
// </p>
// </div>
// );
// }
// }