Created
June 9, 2016 15:01
-
-
Save ruffle1986/22f766bdb57b0ba694557c48d8f213c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const myState = { | |
almafa: 'B' | |
}; | |
const Foo = (props) => ( | |
<div>Hello { props.belmafa }</div> | |
); | |
function myReducer(state = myState, action) { | |
switch (action.type) { | |
case 'foo': | |
return { | |
almafa: 'Foo' | |
}; | |
case 'bar': | |
return { | |
almafa: 'bar' | |
}; | |
default: | |
return state; | |
} | |
} | |
const store = Redux.createStore(myReducer); | |
const Provider = ReactRedux.Provider; | |
store.dispatch({ | |
type: 'foo' | |
}); | |
function map(state) { | |
return { | |
belmafa: state.almafa | |
}; | |
} | |
// How to be reduxed? | |
// You need Provider and connect from react-redux | |
// https://github.com/reactjs/react-redux/blob/master/docs/api.md#provider-store | |
const ConnectedFoo = ReactRedux.connect(map)(Foo); | |
ReactDOM.render( | |
( | |
<Provider store={ store }> | |
<ConnectedFoo /> | |
</Provider> | |
), | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment