-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.js
More file actions
27 lines (22 loc) · 792 Bytes
/
component.js
File metadata and controls
27 lines (22 loc) · 792 Bytes
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
const e = React.createElement;
const useState = React.useState;
const useEffect = React.useEffect;
function Component() {
// State and property setter
const [clicked, setClicked] = useState(0);
// Called at every render
useEffect(() => {
document.title = clicked ? 'useEffect changed this title' : 'React Hooks Experiment';
});
// From now on it's basically "the old render"
if (clicked) {
return e('p', {}, 'useState changed the state of this component. useEffect changed the title of this page.');
}
return e(
'button',
{onClick: () => setClicked(true)},
'Functional Component (Button)'
);
}
const domContainer = document.querySelector('#component_container');
ReactDOM.render(e(Component), domContainer);