Last active
November 18, 2017 22:35
-
-
Save inoh/8fe703f109ba791304c95cd7bb722ae1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component, PropTypes } from 'react'; | |
import { connect } from 'react-redux' | |
import Hello from '../components/Hello'; | |
class App extends Component { | |
static propTypes = { | |
dispatch: PropTypes.func.isRequired, | |
hellos: PropTypes.arrayOf(PropTypes.shape({ | |
value: PropTypes.string.isRequired, | |
note: PropTypes.string.isRequired, | |
})).isRequired, | |
} | |
onClick = () => { | |
const { dispatch } = this.props; | |
// Helloを追加するactionをdispatch(reducer経由でStoreに伝達)する | |
dispatch({ | |
type: 'ADD_HELLO', | |
payload: { | |
value: 'add', | |
note: '追加したよ', | |
}, | |
}); | |
} | |
render() { | |
const { hellos } = this.props; | |
return ( | |
<div> | |
{hellos.map(hello => ( | |
<Hello value={hello.value}> | |
<p>{hello.note}</p> | |
</Hello> | |
))} | |
<br /> | |
<button onClick={this.onClick}>Helloを追加</button> | |
</div> | |
); | |
} | |
} | |
const mapStateToProps = (state) => ({ | |
hellos: state.hellos, | |
}); | |
export default connect(mapStateToProps)(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
初期
追加後