React
HTML
<script src="https://unpkg.com/react@16.12.0/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16.12.0/umd/react-dom.production.min.js"></script>
<div id="app"></div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
.done {
color: rgba(0, 0, 0, 0.3);
text-decoration: line-through;
}
input {
margin-right: 5px;
}
Babel + JSX
function bigArray() {
console.log("new array");
return new ArrayBuffer(10 * 1000 * 1000);
}
class Item extends React.Component {
componentWillUnmount() {
console.log("unmount");
}
render() {
return (
<li>
<label>
<input type="checkbox" disabled readOnly checked={this.props.done} />
<span className={this.props.done ? "done" : ""}>{this.props.text}</span>
</label>
</li>
);
}
}
class TodoApp extends React.Component {
constructor(props) {
super(props)
this.state = {
items: [
{ id: 1, text: "Learn JavaScript", done: true, buffer: bigArray() },
{ id: 2, text: "Learn React", done: true, buffer: bigArray() },
]
}
}
onRefresh() {
this.setState({
items: [
{ id: 3, text: "Check chrome dev tools memory tab - and see more than one JSArrayBufferData (only one should exist)", done: false, buffer: bigArray() }
]
});
}
render() {
return (
<div>
<h2>Todos:</h2>
<ol>
{this.state.items.map(item => <Item key={item.id} text={item.text} done={item.done}/>)}
</ol>
Press this button: <button onClick={() => this.onRefresh()}>Refresh</button>
</div>
)
}
}
ReactDOM.render(<TodoApp />, document.querySelector("#app"))