找不到从this.props解压缩的本地参考

时间:2019-08-07 01:38:04

标签: typescript react-redux

我最近看到此代码无法按预期运行,但正在努力找出原因。我的理解是resetCreateResponse应该引用this.props中的那个。

import { resetCreateResponse } from '../CreateScreen/actions'

interface SuccessScreenProps extends NavigationInjectedProps {
  ...
  resetCreateResponse: () => void
}

class SuccessScreen extends Component<SuccessScreenProps> {
  handleOnDismissPress = async () => {
    const {
      ...,
      resetCreateResponse
    } = this.props
    // await resetCreateResponse() this doesn't work and it seems to points to the one from actions
    await this.props.resetCreateResponse()
  }

  render() {
    return (
      <SuccessModal
        onDismissPress={this.handleOnDismissPress}
      />
    )
  }
}

const mapDispatchToProps = {
  resetCreateResponse,
}

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(SuccessScreen)

动作中的相关代码

type ThunkResult<R> = ThunkAction<R, ReduxState, undefined, Action>

export const resetCreateResponse = (): ThunkResult<void> => async (
  dispatch,
  getState,
) => {
  dispatch(TransactionActions.resetCreateResponse())
}

0 个答案:

没有答案