Skip to content

Instantly share code, notes, and snippets.

@isabellachen
Created November 19, 2019 15:53
Show Gist options
  • Save isabellachen/db7968a9e7b42f9b8a1524a5301789cc to your computer and use it in GitHub Desktop.
Save isabellachen/db7968a9e7b42f9b8a1524a5301789cc to your computer and use it in GitHub Desktop.
Extend component props with props from react router and react i18n with react typescript
import { WithTranslation, withTranslation, useTranslation } from 'react-i18next';
import { RouteComponentProps, withRouter } from 'react-router-dom';
export type MyDemoProps = {} & RouteComponentProps & WithTranslation;
function MyDemoComponent({
history,
t,
}: MyDemoProps) {
const [t] = useTranslation(); //alternatively, import translation function directly into component
return <div>DEMO COMPONENT</div>
}
export const MyDemo = withTranslation()(
withRouter(MyDemoComponent),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment