File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
app/javascript/components Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
import PropTypes from "prop-types" ;
3
+ import { connect } from "react-redux" ;
4
+ import { createStructuredSelector } from "reselect" ;
5
+
6
+ const GET_GREETINGS_REQUEST = "GET_GREETINGS_REQUEST" ;
7
+
8
+ function getGreetings ( ) {
9
+ console . log ( 'getGreetings(), Action!' ) ;
10
+ return {
11
+ type : 'GET_GREETINGS_REQUEST'
12
+ } ;
13
+ } ;
3
14
4
15
class Greeting extends React . Component {
5
16
render ( ) {
6
17
return (
7
18
< React . Fragment >
8
19
Greeting Message: { this . props . greetingMessage }
20
+ < button className = "btn btn-more" onClick = { ( ) => this . props . getGreetings ( ) } > Get another greeting</ button >
9
21
</ React . Fragment >
10
22
) ;
11
23
}
12
24
}
13
25
26
+ const structuredSelector = createStructuredSelector ( {
27
+ greetings : state => state . greetings ,
28
+ } ) ;
29
+
30
+ const mapDispatchToProps = { getGreetings } ;
31
+
14
32
Greeting . propTypes = {
15
33
greetingMessage : PropTypes . string
16
34
} ;
17
35
18
- export default Greeting ;
36
+ export default connect ( structuredSelector , mapDispatchToProps ) ( Greeting ) ;
You can’t perform that action at this time.
0 commit comments