-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathToggle.tsx
27 lines (23 loc) · 882 Bytes
/
Toggle.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
import React from 'react';
import { connect } from 'react-redux';
import { ActionCreator, bindActionCreators, Dispatch } from 'redux';
import { IReduxToggleMessageAction, toggleMessage } from './actions';
import { AppState } from './rootReducer';
const Toggle: React.FC<{ messageVisibility: boolean; toggleMessage: ActionCreator<IReduxToggleMessageAction> }> = ({
messageVisibility,
toggleMessage
}) => (
<div>
{messageVisibility && <p>You will be seeing this if redux action is toggled</p>}
<button onClick={toggleMessage}>Toggle Me</button>
</div>
);
const mapStateToProps = (state: AppState) => ({
messageVisibility: state.message.messageVisibility
});
const mapDispatchToProps = (dispatch: Dispatch<IReduxToggleMessageAction>) =>
bindActionCreators({ toggleMessage }, dispatch);
export default connect(
mapStateToProps,
mapDispatchToProps
)(Toggle);