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.

[Link] Improve integration with Next.js

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Passing an URL object to the MUI button component, as in the code below, works without problems but you get the following error: Warning: Failed prop type: Invalid prop `href` of type `object` supplied to `ForwardRef(ButtonBase)`, expected `string`.

// index.js
import React from "react";
import Button from "@material-ui/core/Button";
import Link from "../src/Link";

export default function Index() {
  return (
    <div>
      <Button
        component={Link}
        href={{
          pathname: "/about",
          query: { name: "test" }
        }}
        naked
        variant="contained"
      >
        Link button with url object
      </Button>
    </div>
  );
}

Note: The imported Link component is the same as the one in the NextJS - Material UI integration example.

Expected Behavior 🤔

No error should appear.

Steps to Reproduce 🕹

CodeSandbox reproduction: https://codesandbox.io/s/next-materialui-objecturl-rmprr?file=/pages/index.js

Context 🔦

In the NextJS documentation I learned that we can use an URL object and it will get formatted automatically to create an URL string.

Using URL objects instead of strings has helped me to handle complex queries mutations easily and intuitively.

Your Environment 🌎

`npx @material-ui/envinfo`
  System:
    OS: Windows 10 10.0.17763
  Binaries:
    Node: 15.0.1 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Not Found
  npmPackages:
    @material-ui/core: ^4.11.2 => 4.11.2
    @material-ui/icons: ^4.11.2 => 4.11.2
    @material-ui/lab: ^4.0.0-alpha.57 => 4.0.0-alpha.57
    @material-ui/styles:  4.11.2
    @material-ui/system:  4.11.2
    @material-ui/types:  5.1.0
    @material-ui/utils:  4.11.2
    @types/react:  17.0.0
    react: ^17.0.1 => 17.0.1
    react-dom: ^17.0.1 => 17.0.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
kelvinsanchez15commented, Dec 23, 2020

Yeah I would like it. Just to be clear, I would have to update both NextJS examples (with and without TypeScript), and replace the line of code in the ButtonBase.js file?

1reaction
kelvinsanchez15commented, Dec 24, 2020

Perfect, it seems like the right option to me too. @oliviertassinari

I just did a JS version, the only thing I’m not totally sure about, are both NextLinkComposed.propTypes and Link.propTypes objects, so tell me if changes are need it there: https://codesandbox.io/s/next-materialui-objecturl-forked-7qk0b?file=/src/Link.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Link] Improve integration with Next.js · Issue #24106 - GitHub
The first option is more consistent for both users, the second makes JS users able to use the 'href' prop without problems (Just...
Read more >
Advanced Features: Next.js Compiler
The Next.js Compiler, written in Rust using SWC, allows Next.js to transform and minify your JavaScript code for production. This replaces Babel for...
Read more >
Link Component - Navigate Between Pages | Learn Next.js
<Link> allows you to do client-side navigation and accepts props that give you better control over the navigation behavior.
Read more >
Basic Features: Handling Scripts - Next.js
next /link ... Streaming and Suspense improve page performance by rendering and ... This can improve the performance of your site by dedicating...
Read more >
Advanced Features: Custom Server - Next.js
A custom Next. js server allows you to start a server 100% programmatically in order to use custom server patterns.
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