summaryrefslogtreecommitdiff
path: root/preact/demo/key_bug.js
blob: 0ccb1a60f716c9604ef3d00d43f254e9beb6cf4f (plain)
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
import { createElement, Component } from 'preact';

function Foo(props) {
	return <div>This is: {props.children}</div>;
}

export default class KeyBug extends Component {
	constructor() {
		super();
		this.onClick = this.onClick.bind(this);
		this.state = { active: false };
	}

	onClick() {
		this.setState(prev => ({ active: !prev.active }));
	}

	render() {
		return (
			<div>
				{this.state.active && <Foo>foo</Foo>}
				<h1>Hello World</h1>
				<br />
				<Foo>
					bar <Foo>bar</Foo>
				</Foo>
				<br />
				<button onClick={this.onClick}>Toggle</button>
			</div>
		);
	}
}