使用 Flowtype 覆盖 React-Redux Connect()
Covering React-Redux Connect() using Flowtype
我有以下代码:
const mapStateToFilterProps = (state:DataExplorerState, props) => ({ loading: state.loading, filters: state.filters });
const actionCreators: ActionCreators<string, Action> = { updateLoadState, updateFilters, updateChartData};
const mapDispatchToProps = (dispatch: Dispatch<Action>) => bindActionCreators(actionCreators, dispatch)
// TODO: Fix typing issue
export const FilterBoxConnect = connect(
mapStateToFilterProps,
mapDispatchToProps
)(FilterBox)
"TODO" 下方的代码表示未发现。我怎样才能覆盖它?
我认为它被发现是因为 connect
在 0.85 之前不需要被显式注释。 0.85之后,Flow会ask for required annotations。基本上,如果我们没有在导出时显式注释连接的组件,Flow 将报告 "implicitly instantiated" 错误:
Missing type annotation for OP. OP is a type parameter declared in function type [1] and was implicitly
instantiated at call of connect [2].
此外,我们现在可以通过提供类型参数来显式注释 connect
。
import * as React from 'react'
type OwnProps = {|
passthrough: string,
forMapStateToProps: string
|}
type Props = {|
...OwnProps,
fromMapStateToProps: string,
dispatch1: () => void
|}
const MyComponent = (props: Props) => (
<div onClick={props.dispatch1}>
{props.passthrough}
{props.fromMapStateToProps}
</div>
)
export default connect<Props, OwnProps, _, _, _, _>(
mapStateToProps,
mapDispatchToProps
)(MyComponent)
我有更详细的指南here。
我有以下代码:
const mapStateToFilterProps = (state:DataExplorerState, props) => ({ loading: state.loading, filters: state.filters });
const actionCreators: ActionCreators<string, Action> = { updateLoadState, updateFilters, updateChartData};
const mapDispatchToProps = (dispatch: Dispatch<Action>) => bindActionCreators(actionCreators, dispatch)
// TODO: Fix typing issue
export const FilterBoxConnect = connect(
mapStateToFilterProps,
mapDispatchToProps
)(FilterBox)
"TODO" 下方的代码表示未发现。我怎样才能覆盖它?
我认为它被发现是因为 connect
在 0.85 之前不需要被显式注释。 0.85之后,Flow会ask for required annotations。基本上,如果我们没有在导出时显式注释连接的组件,Flow 将报告 "implicitly instantiated" 错误:
Missing type annotation for OP. OP is a type parameter declared in function type [1] and was implicitly
instantiated at call of connect [2].
此外,我们现在可以通过提供类型参数来显式注释 connect
。
import * as React from 'react'
type OwnProps = {|
passthrough: string,
forMapStateToProps: string
|}
type Props = {|
...OwnProps,
fromMapStateToProps: string,
dispatch1: () => void
|}
const MyComponent = (props: Props) => (
<div onClick={props.dispatch1}>
{props.passthrough}
{props.fromMapStateToProps}
</div>
)
export default connect<Props, OwnProps, _, _, _, _>(
mapStateToProps,
mapDispatchToProps
)(MyComponent)
我有更详细的指南here。