summaryrefslogtreecommitdiff
path: root/preact/demo/key_bug.js
diff options
context:
space:
mode:
Diffstat (limited to 'preact/demo/key_bug.js')
-rw-r--r--preact/demo/key_bug.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/preact/demo/key_bug.js b/preact/demo/key_bug.js
new file mode 100644
index 0000000..0ccb1a6
--- /dev/null
+++ b/preact/demo/key_bug.js
@@ -0,0 +1,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>
+ );
+ }
+}