question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HeaderMenuItem element bug with typescript

See original GitHub issue

Hello, I am using the latest version of carbon-components-react v7.10.2 with typescript.

I have the following issue, when I pass element prop element={NavLink} and I got the following error:

Screenshot 2020-03-20 at 11 15 39

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
tulio-coppolacommented, Jun 10, 2020

To anyone who finds this.

@ilievZlatko’s problem occurs when using Carbon in a TS project.

Your issue is probably related to this: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44772

You just need to import the LinkProps from react-router-dom (it will probably work with NavLinkProps as well) and use it with the Carbon component. It even works with React Router v6.0.0-alpha.5 (yarn add react-router@next react-router-dom@next as of today)

Example:

import { Link, LinkProps } from 'react-router-dom';

const MainHeader: React.FC = () => (
  <Header aria-label="Carbon Tutorial">
    <SkipToContent />
    <HeaderName<LinkProps> element={Link} to="/" prefix="IBM">
      Carbon Tutorial
    </HeaderName>
    <HeaderNavigation aria-label="Carbon Tutorial">
      <HeaderMenuItem<LinkProps> element={Link} to="repos">
        Repositories
      </HeaderMenuItem>
    </HeaderNavigation>
    <HeaderGlobalBar>
      <HeaderGlobalAction aria-label="Notifications">
        <Notification20 />
      </HeaderGlobalAction>
      <HeaderGlobalAction aria-label="User Avatar">
        <UserAvatar20 />
      </HeaderGlobalAction>
      <HeaderGlobalAction aria-label="App Switcher">
        <AppSwitcher20 />
      </HeaderGlobalAction>
    </HeaderGlobalBar>
  </Header>
);

export default MainHeader;

Image of the code above:

Screen Shot 2020-06-09 at 21 58 56
0reactions
Daveianocommented, Dec 18, 2021

This actually works for both <HeaderName> and <SideNavLink>

For <SideNavLink> you to apply it the same:

import { Link, LinkProps } from "react-router-dom";

<SideNavLink<LinkProps> renderIcon={ChartTreemap32}  to="/" element={Link}>
  Overview
</SideNavLink>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript and destructured variables not recognising props
I have a function that returns data . The object that gets returned contains headerMenu, page, content and ...
Read more >
1. Installing Carbon
Welcome to Carbon! This tutorial will guide you in creating a React app with the Carbon Design System.
Read more >
cannot be used as a jsx component. its return type 'element
Describe the Bug. When using the Link component with TypeScript in a JSX file you will get an error: 'NextLink' cannot be used...
Read more >
Tooltip Component - Angular Data Grid
Feb 8. What's new in AG Grid 27.0.0. Major release with new features and bug fixes. 100% React Rendering; Typescript Example ...
Read more >
Releases | Adjust Atlas
Bug fixes​. Fixed input's width to be 100% when ComboBox component is in input kind so that it looks like a usual input...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found