-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhyperapp.js
More file actions
33 lines (27 loc) · 718 Bytes
/
hyperapp.js
File metadata and controls
33 lines (27 loc) · 718 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
28
29
30
31
32
33
import React, { useState } from "react";
import ReactDOM from "react-dom";
function useApp(initialState, actionsDefs) {
const [state, setState] = useState(initialState);
let actions = {};
for (const name in actionsDefs) {
const action = actionsDefs[name];
actions[name] = value => {
const result = action(value)(state, actions);
if (result !== undefined) {
setState(result);
}
};
}
return {
state,
actions
};
}
export function app(initialState, actionsDefs, view, element) {
function App() {
const { state, actions } = useApp(initialState, actionsDefs);
return view(state, actions);
}
ReactDOM.render(<App />, element);
}
export { React };