-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading.jsx
More file actions
42 lines (35 loc) · 1.08 KB
/
Copy pathloading.jsx
File metadata and controls
42 lines (35 loc) · 1.08 KB
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
import React from 'react';
import { connect } from 'react-redux';
// TODO:
// inteegrate something like this
// https://github.com/Rezonans/redux-async-connect
const loading = (action) => (Component) => {
const Wrapper = React.createClass({
getInitialState() {
return {
loading: true,
};
},
componentWillMount() {
const {
params,
location: { query },
dispatch,
} = this.props;
if (Array.isArray(action)) {
Promise.all(
action.map(oneAction => dispatch(oneAction(params, query)))
).then(() => this.setState({ loading: false }));
} else {
dispatch(action(params, query)).then(() => this.setState({ loading: false }));
}
},
render() {
return this.state.loading
? <div>loading...</div>
: <Component {...this.props} />;
},
});
return connect(null)(Wrapper);
};
export default loading;