File tree Expand file tree Collapse file tree 4 files changed +34
-15
lines changed
Expand file tree Collapse file tree 4 files changed +34
-15
lines changed Original file line number Diff line number Diff line change 1+
2+ export const updateBackgroundColor = ( hex ) => ( {
3+ type : "UPDATE_BACKGROUND_COLOR" ,
4+ hex
5+ } )
Original file line number Diff line number Diff line change @@ -2,31 +2,35 @@ import React from 'react';
22import { connect } from 'react-redux' ;
33import creater from '../components/creater' ;
44import { SketchPicker } from 'react-color' ;
5+ import { updateBackgroundColor } from '../actions' ;
56
6- const handleChangeComplete = ( color ) => {
7- console . log ( color . hex ) ;
8- return {
9- background : color . hex
10- } ;
11- }
7+ // const handleChangeComplete = (color) => {
8+ // console.log(color.hex);
9+ // dispatch(updateBackgroundColor(color.hex));
10+ // return {
11+ // background: color.hex
12+ // };
13+ // }
1214
13- const Controller = ( ) => {
15+ const Controller = ( { updateBackgroundColor } ) => {
1416 let backgroundColor = 'red' ;
1517 return (
1618 < div >
1719 Controller
1820 < SketchPicker
1921 color = { backgroundColor }
20- onChangeComplete = { handleChangeComplete }
22+ onChangeComplete = { ( color ) => updateBackgroundColor ( color . hex ) }
2123 />
2224 < button onClick = { ( ) => creater ( 'my-node' ) } > CREATE</ button >
23-
24-
2525 </ div >
2626 )
2727}
28- const mapStateToProps = ( state ) => state
29- const mapDispatchToProps = ( dispatch ) => ( { } ) ;
28+
29+ const mapStateToProps = ( state ) => ( { backgroundColor : state . backgroundColor } ) ;
30+
31+ const mapDispatchToProps = ( dispatch ) => ( {
32+ updateBackgroundColor : ( hex ) => dispatch ( updateBackgroundColor ( hex ) )
33+ } ) ;
3034
3135export default connect (
3236 mapStateToProps ,
Original file line number Diff line number Diff line change 1+ export const updateBackgroundColor = ( state = [ ] , action ) => {
2+ switch ( action . type ) {
3+ case "UPDATE_BACKGROUND_COLOR" :
4+ return action . hex ;
5+ default :
6+ return state ;
7+ }
8+ }
9+
Original file line number Diff line number Diff line change 11import { combineReducers } from 'redux' ;
2+ import { updateBackgroundColor } from './background' ;
23
3- export default combineReducers ( { }
4- //
5- ) ;
4+ export default combineReducers ( {
5+ updateBackgroundColor
6+ } ) ;
You can’t perform that action at this time.
0 commit comments