Material-ui: IconButton & React Router Link

Created on 14 Jan 2016  路  5Comments  路  Source: mui-org/material-ui

I have a toolbar with several IconButtons and I'm trying to turn them into react router <Link>s.

I tried the syntax @hai-cea posted in issue #908, but unfortunately it's causing my icon button to render at 0x0 px.

working JSX before:

<IconButton tooltip="Listings">
         <ListingsIcon color='white' />
</IconButton>

non-working JSX after:

<IconButton
         tooltip="Listings"
         containerElement={<Link to="/listings" />}
         linkButton={true}>

         <ListingsIcon color='white'/>
</IconButton>

and the icon button vanishes. It's still in the DOM according to React Tools, but every element in the hierarchy (<IconButton><EnhancedButton><Router>) is rendering at 0x0 px.

pretty new w/ React so apologies if this is an obvious mistake on my part, but have come up empty on my own research/troubleshooting.

question

Most helpful comment

turns out the problem boiled down to this:

wrong:
import Link from 'react-router

right:
import { Link } from 'react-router

ah, afternoon well spent. fml.

All 5 comments

turns out the problem boiled down to this:

wrong:
import Link from 'react-router

right:
import { Link } from 'react-router

ah, afternoon well spent. fml.

@brandonmp if you use eslint, this plugin (and an editor that points out eslint transgressions) may be useful to bring that kind of thing to your attention sooner

For future readers, the way to do it now (material-ui 4) is:

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

<IconButton
  component={Link}
  to='/path'
>
  <Delete />
</IconButton>

@oliviertassinari I've found the routing libraries link before luckily finding this issue report; while the explanation given in the routing libraries surely is comprehensive I found it to be completely over my head as a relatively newcomer. However, @moshfeu's example is concise and exactly what I'm looking for. Anything wrong with his simple example?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranBran picture FranBran  路  3Comments

finaiized picture finaiized  路  3Comments

newoga picture newoga  路  3Comments

mb-copart picture mb-copart  路  3Comments

ghost picture ghost  路  3Comments