-
Notifications
You must be signed in to change notification settings - Fork 46
/
Switcher.js
executable file
·34 lines (29 loc) · 896 Bytes
/
Switcher.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
import React from 'react'
import { connect } from 'react-redux'
import { TransitionGroup, Transition } from 'transition-group'
import universal from 'react-universal-component'
import Loading from './Loading'
import Err from './Error'
import isLoading from '../selectors/isLoading'
import styles from '../css/Switcher'
const UniversalComponent = universal(({ page }) => import(`./${page}`), {
minDelay: 500,
loading: Loading,
error: Err
})
const Switcher = ({ page, direction, isLoading }) =>
<TransitionGroup
className={`${styles.switcher} ${direction}`}
duration={500}
prefix='fade'
>
<Transition key={page}>
<UniversalComponent page={page} isLoading={isLoading} />
</Transition>
</TransitionGroup>
const mapState = ({ page, direction, ...state }) => ({
page,
direction,
isLoading: isLoading(state)
})
export default connect(mapState)(Switcher)