markdown 如何使用Flow轻松键入Redux Props

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 如何使用Flow轻松键入Redux Props相关的知识,希望对你有一定的参考价值。

# How to easily type Redux Props with Flow

## Add ExtractReturn helper

```jsx
// https://hackernoon.com/redux-flow-type-getting-the-maximum-benefit-from-the-fewest-key-strokes-5c006c54ec87
// https://github.com/facebook/flow/issues/4002
// eslint-disable-next-line no-unused-vars
type _ExtractReturn<B, F: (...args: any[]) => B> = B;
export type ExtractReturn<F> = _ExtractReturn<*, F>;
```

## Extract return of mapStateToProps and mapDispatchToProps

```jsx
const mapStateToProps = state => ({
  user: state.user,
});
const mapDispatchToProps = dispatch => ({
  actions: {
    logout: () => dispatch(logout()),
  },
});

type ReduxProps = ExtractReturn<typeof mapStateToProps>;
type ReduxActions = ExtractReturn<typeof mapDispatchToProps>;
```

## Add ReduxProps and ReduxActions to your Component props

```jsx
type Props = {} & ReduxProps & ReduxState

class EntriaComp extends Component<Props> {}
```

以上是关于markdown 如何使用Flow轻松键入Redux Props的主要内容,如果未能解决你的问题,请参考以下文章

将组件作为道具传递时在 Flow 中键入 React 组件

markdown 使用git flow

如何键入类或构造函数

markdown 使用`git flow`命令与raw`git`命令的比较。

markdown Authenticate - Flow Flow Social Streams WordPress插件

markdown git flow