-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.tsx
62 lines (53 loc) · 1.26 KB
/
index.tsx
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
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, Store } from 'redux'
import { connect, Provider } from 'react-redux'
import AnimateOnChange from '../index.js'
const initialState = {
diff: 0,
score: 0
}
interface Action {
type: string,
diff: number
}
const reducer = (state = initialState, action: Action) => {
switch (action.type) {
case 'INCREMENT_SCORE':
return { ...state,
diff: action.diff,
score: state.score + action.diff }
default:
return state
}
}
const store: Store<typeof initialState, Action> = createStore(reducer)
setInterval(() => {
store.dispatch({
type: 'INCREMENT_SCORE',
diff: 10
})
}, 2000)
interface Props {
diff: number,
score: number,
}
function handleClick(): void {
console.log('click!');
}
const AppComponent = ({ diff, score }: Props) =>
<div className='App'>
<AnimateOnChange
baseClassName='Score'
animationClassName='Score--bounce'
animate={diff !== 0}
id="example-id"
onClick={handleClick}
>
Score: {score}
</AnimateOnChange>
</div>
const App = connect(s => s)(AppComponent)
// @ts-ignore
ReactDOM.render(<Provider store={store}><App/></Provider>,
document.getElementById('root'))