-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (54 loc) · 1.63 KB
/
index.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import { PageHeader } from 'react-bootstrap';
import rootReducer from './reducers';
import ExportJSON from './components/Export';
import Create from './components/Create';
import ViewNav from './components/ViewNav';
import Preview from './components/Preview';
import './index.css';
// the store holds state for the form-builder application,
// questions and view are reducers
// ************* REACT COMPONENTS *************
class FormBuilder extends React.Component {
render() {
const { store } = this.props;
const { dispatch } = store;
const { view, questions } = store.getState();
// const { questions } =
console.log(store.getState()); // FIXME REMOVE ME EVENTUALLY
return (
<div>
<div>
<PageHeader>
Form Builder 0.1
</PageHeader>
</div>
<div>
<ViewNav dispatch={dispatch} />
</div>
<div>
{/* FIXME */}
{ view === 'CREATE' ? <Create store={store} /> : null}
{ view === 'EXPORT' ? <ExportJSON questions={questions} /> : null}
{ view === 'PREVIEW' ? <Preview store={store} /> : null}
</div>
</div>
);
}
}
const store = createStore(rootReducer);
// ***************** END REACT COMPONENTS *****************
// define a render function that can be subscribed, and will be reacalled after
// any update to the store's state.
const render = () => {
ReactDOM.render(
<FormBuilder
store={store}
/>,
document.getElementById('root')
);
};
store.subscribe(render);
render();