Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mapDispatchToProps = (dispatch) => {
- return{
- what goes in here?
- }
- }
- export default connect(mapStateToProps, mapDispatchToProps)(ComponentName);
- export const change = value =>({
- type: 'CHANGE_FRUIT',
- fruit : value
- })
- import { change as changeFruit } from './actions/fruit'
- const mapDispatchToProps = dispatch =>({
- change : fruit => dispatch(changeFruit(fruit))
- })
- dispatch(changeFruit('apple'))
- import { change as changeFruit } from './actions/fruit'
- class Component extends React.component{
- render(){
- const { fruit, change } = this.props
- return(
- <>
- <div>{fruit}</div>
- <button onClick={() => change('orange')}>Change to orange</button>
- </>
- )
- }
- }
- const mapStateToProps = state =>({
- fruit : state.fruit
- })
- const mapDispatchToProps = dispatch =>({
- change : fruit => dispatch(changeFruit(fruit))
- })
- export default connect(mapStateToProps, mapDispatchToProps)(Component)
- import youraction from './youraction';
- componentDidMount() {
- this.props.youractionhandler(action incoming args for example id)
- }
- const mapDispatchToProps = dispatch => ({
- youractionhandler: action incoming args for example id => dispatch(youraction(action incoming args for example id))
- })
- export default connect(mapStateToProps, mapDispatchToProps)(ComponentName);
- {
- type: 'ADD_TEXT',
- value: 'red delicious'
- }
- const addText = value => ({ type: 'ADD_TEXT', value })
- const action = addText('red delicious') // Create the plain action object
- dispatch(action) // Send it to the reducers
- const mapDispatchToProps = dispatch => ({
- addText: value => {
- // Same code as above:
- const action = addText('red delicious')
- dispatch(action)
- }
- })
- props.addText('red delicious')
- <Provider store={store}>
- const mapDispatchToProps = (dispatch) => {
- return{
- example look this is dispatch that well happened it will call specif action bu use key type
- this == store.dispatch(constants.WIDITHROUP)
- the first is key or name of the handle when you want to implement :(input that enters fro this dispatch and=> it call store.dispatch(name of Handel) )
- widthroup: (balance) => dispatch({ type: constants.WIDITHROUP ,balance}),
- deposit: (balance) => dispatch({ type: constants.DEPOSIT,balance }) }
- }
- }
- return {
- what goes in here?
- }
- class ColorSelector {
- saveSelection () {
- dispatch(action); //dispatch is some way to dispatch an action
- }
- }
- //I pass my selected color to saveSelection method and that should save
- saveSelection(dataToUpdate) {
- dispatch({type: actionType, data: dataToUpdate})
- }
- saveSelectionAction(dataToUpdate) {
- return {type: actionType, data: dataToUpdate}
- }
- saveSelection(dataToUpdate) {
- dispatch(saveSelectionAction(dataToUpdate))
- }
- anotherMethodWhichPassesDispatch(dispatch) {
- // unleash the power of closure
- return {
- saveSelection: saveSelection(dataToUpdate) {
- dispatch(saveSelectionAction(dataToUpdate))
- }
- }
- }
- anotherMethodWhichPassesDispatch(dispatch) {
- return {
- saveSelection: (dataToUpdate) => {
- dispatch(saveSelectionAction(dataToUpdate))
- }
- }
- }
- saveSelection = (selectedColor) => {
- this.props.saveSelection(selectedColor);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement