Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: Prop `className` did not match. when using styled components with semantic-ui-react

I use this code to margin my Button from top:

const makeTopMargin = (elem) => {
    return styled(elem)`
        && {
            margin-top: 1em !important;
        }
    `;
}

const MarginButton = makeTopMargin(Button);

and whenever i use MarginButton node, I get this error: Warning: PropclassNamedid not match. Server: "ui icon left labeled button sc-bwzfXH MjXOI" Client: "ui icon left labeled button sc-bdVaJa fKCkqX"

You can see this produced here.

What should I do?

like image 841
Talha Talip Açıkgöz Avatar asked Aug 10 '18 17:08

Talha Talip Açıkgöz


2 Answers

This warning was fixed for me by adding an .babelrc file in the project main folder, with the following content:

{
  "presets": ["next/babel"],
  "plugins": [["styled-components", { "ssr": true }]]
}

See following link for an example: https://github.com/nblthree/nextjs-with-material-ui-and-styled-components/blob/master/.babelrc

like image 61
C. Molendijk Avatar answered Oct 23 '22 07:10

C. Molendijk


Or you could just add this to your next.config.js. This also makes it so next-swc (speedy web compiler) works to reduce build times. See more here.

// next.config.js
module.exports = {
  compiler: {
    // Enables the styled-components SWC transform
    styledComponents: true
  }
}
like image 36
Alex Cory Avatar answered Oct 23 '22 05:10

Alex Cory