Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pass additional props. #107

Closed
AudriusDai opened this issue May 19, 2020 · 3 comments
Closed

Unable to pass additional props. #107

AudriusDai opened this issue May 19, 2020 · 3 comments
Labels
types issues with TS or Flow defs

Comments

@AudriusDai
Copy link

When using typescript I am unable to pass down the additional props to component wrapped in withBreadcrumbs method.

interface CustomProps<T> extends InjectedProps<T> {
    rightNode?: ReactNode;
}
const CustomCrumbsHeader = (props: CustomProps<any>) => {
..
}

export default  withBreadcrumbs(breadcrumbsConfig, { disableDefaults: true })(CustomCrumbsHeader);
// following prop 'rightNode' is NOT accepted.
<DefaultedCustomCrumbsHeader rightNode={null} /> 

error message:

Type '{ rightNode: null; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<InjectedProps<unknown>, never>, any, any>> & Readonly<...> & Readonly<...>'.
  Property 'rightNode' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<InjectedProps<unknown>, never>, any, any>> & Readonly<...> & Readonly<...>'.  TS2322

Question: Am I doing something wrong here? How to properly pass the additional props?

The only way I've found it to work is to proxy the props with spread:

interface CustomPropsNew {
    rightNode?: ReactNode;
}
const A = withBreadcrumbs(breadcrumbsConfig, { disableDefaults: true })(CustomCrumbsHeader);
const B = (props: CustomPropsNew) => <A {...props} />;

export default B;
// 'rightNode' is now accepted.
<DefaultedCustomCrumbsHeader rightNode={null} /> 

Dependencies:

..
"react": "^16.13.1",
"react-router-breadcrumbs-hoc": "^3.2.10",
"react-router-dom": "^5.1.2",
// devDependencies
"typescript": "^3.5.2"
..
@AudriusDai
Copy link
Author

As an alternative I was able to use use-react-router-breadcrumbs. It was way easier :)

@icd2k3
Copy link
Owner

icd2k3 commented May 20, 2020

Thanks @AudriusDai - I'll update this repo soon to use the same generated types like use-react-router-breadcrumbs has

@icd2k3 icd2k3 added the types issues with TS or Flow defs label May 20, 2020
@icd2k3
Copy link
Owner

icd2k3 commented Jun 3, 2020

Should be fixed as of 3.3.0

@icd2k3 icd2k3 closed this as completed Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types issues with TS or Flow defs
Projects
None yet
Development

No branches or pull requests

2 participants