markdown Redux容器示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Redux容器示例相关的知识,希望对你有一定的参考价值。

# Connect ( Container )

```jsx
import { connect } from 'react-redux';
import { compose } from 'recompose';
import { numberOfItemsInCartSelector, totalPriceForCartItemsSelector } from '_redux/rootReducer';

const mapStateToProps = (state) => {
    return {
        numberOfItemsInCart: numberOfItemsInCartSelector(state),
        totalPrice: totalPriceForCartItemsSelector(state),
    }
}

const  mapDispatchToProps  = (dispatch) => ({
    addToCart: (product, quantity) =>  dispatch(addToCart(product, quantity))
})

export const CartInfoContainer = compose(
    connect(
        mapStateToProps, mapDispatchToProps
    )
)
```


# MapDispatchToProps
examples

```jsx
const  mapDispatchToProps  = (dispatch) => ({
    addToCart: (product, quantity) =>  dispatch(addToCart(product, quantity))
})
```

```jsx
const mapDispatchToProps = {
    hideFloatSideBar,
};
```

以上是关于markdown Redux容器示例的主要内容,如果未能解决你的问题,请参考以下文章

Redux,如果我想访问数据,是不是必须在所有容器中导入存储?

markdown Redux动作模式

markdown Redux Dev Tools

markdown 介绍一个React y Redux

markdown redux_slide.md

markdown Redux东西