react-nativei18nextreact-i18next

react-i18next use withTranslation got type and ref error, I don't how to fix


after use withTranslation, react-native ts got errors, ref error and type error, I don't know how to fix

enter image description here

enter image description here

    "i18next": "^23.5.0",
    "react": "18.2.0",
    "react-i18next": "^13.2.2",
    "react-native": "0.72.4",

Solution

  • find a way to solve the two errors while use ts and ref and class component with react-i18next withTranslation

    datePickerRef: React.RefObject<DatePickerRef> = React.createRef<DatePickerRef>();
    
    //region withTranslation with ts and ref
    //https://github.com/i18next/react-i18next/blob/fdab4e8953b2cdaf29d21d716d33ebfd0eca99f2/src/withTranslation.js#L5
    //https://stackoverflow.com/questions/77677338/react-i18next-use-withtranslation-got-type-and-ref-error-i-dont-how-to-fix
    //https://github.com/i18next/react-i18next/issues/1122#issuecomment-1859634674
    export interface DatePickerRef extends DatePicker {}
    export default withTranslation(undefined, { withRef: true })(DatePicker) as React.ForwardRefExoticComponent<
      Omit<DatePickerProps, keyof WithTranslation> & RefAttributes<DatePickerRef>
    >;
    //endregion