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.

[Typescript] Breadcrumbs `as` parameter does not work with Reach Router as documented

See original GitHub issue

Describe the bug Typescript claims a type error when attempting to use Link from @reach/router in the BreadcrumbLink as parameter as documented here

This may also affect other components which use Link

Error:

Type 'typeof Link' is not assignable to type '"symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | ... 157 more ... | undefined'.
  Type 'typeof Link' is not assignable to type 'ComponentClass<any, any> & string'.
    Type 'typeof Link' is not assignable to type 'string'.

Expected Behavior The types should match to allow use as documented and as allowed in JS.

To Reproduce

  • Use this template:

yarn create react-app bug-demo --typescript

Install chakra-ui as documented Use this component:

import React from 'react'
import {Breadcrumb, BreadcrumbItem, BreadcrumbLink} from '@chakra-ui/core'
import {Link} from '@reach/router'

export const Bug = () => (
  <Breadcrumb>
    <BreadcrumbItem>
      <BreadcrumbLink as={Link} to="/">Test</BreadcrumbLink>
    </BreadcrumbItem>
  <Breadcrumb>
)
  • List the steps to reproduce the behavior: yarn start

Suggested solution(s)

Change the typing on as to be more inclusive. Perhaps ReactNode instead of ElementType

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
segunadebayocommented, Feb 26, 2020

Hi @DavidJFelix,

I’m going to close this considering it’s a duplicate in the #205 issue. We’ve resolved this permanently in the TypeScript branch. It should be released by next month.

Thanks

3reactions
DavidJFelixcommented, Feb 1, 2020

unstale. this still exists with a number of link-based components when using reach

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reach Router
This is useful for Routers rendered as asides, headers, breadcrumbs etc. but not the main content.
Read more >
Dynamic breadcrumbs using react router - Stack Overflow
We have to recursively flatten navigation and render it a flat array: const routes = flattenRoutes(navigation); return (<Router> {routes. map(( ...
Read more >
use-react-router-breadcrumbs - npm
Add breadcrumbs to your existing route object. This is a great way to keep all routing config paths in a single place! If...
Read more >
Building Dynamic Breadcrumbs in NextJS - DEV Community ‍ ‍
Breadcrumbs are a website navigation tool that allows users to see their current page's "stack" of how it is nested under any parent...
Read more >
Automatically generating a breadcrumb with React Router
Providing the user a path of going back in a UI is a must, so adding a navigational element that shows the route...
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