【问题标题】:withNavigationFocus throwing lint error - React Native TypescriptwithNavigationFocus 抛出 lint 错误 - React Native Typescript
【发布时间】:2023-09-13 13:24:01
【问题描述】:

我正在尝试将 withNavigationFocus 用于组件,因为代码是用 Typescript 编写的。 ,

我的组件道具

   interface IScreenProps {
  navigation: NavigationScreenProp<NavigationState, IParamsNavigate>;
  departments: NavigationNode[] | null;
  updateSearchCriteria: (searchCriteria: ISearchCriteria, stack: StackNames) => void;
  resetProductState: () => void;
  isFocused: boolean;
}

组件

class SearchScreen extends React.Component<IScreenProps, IScreenState> {

.....

}

export default connect(mapStateToProps, mapDispatchToProps)( withNavigationFocus(SearchScreen));

没有构建错误,在 searchScreen 导出的编辑器/IDE 中仍然显示红线。 .我在下面附上了我面临的错误。

请告诉我如何解决这个问题。

【问题讨论】:

    标签: typescript react-native ecmascript-6 types react-navigation


    【解决方案1】:

    使用NavigationStackProp(或根据您的导航器使用的相关名称),而不是NavigationScreenProp

    interface IScreenProps {
      navigation: NavigationStackProp<IParamsNavigate>;
      departments: NavigationNode[] | null;
      updateSearchCriteria: (searchCriteria: ISearchCriteria, stack: StackNames) => void;
      resetProductState: () => void;
      isFocused: boolean;
    }
    

    https://reactnavigation.org/docs/en/4.x/typescript.html

    【讨论】:

    • 我正在使用 react-navigation v3。 NavigationStackProp 不可用。请建议一些其他相关的解决方案