styled-components is saying wrapped styled() around your React component (Component)












2















I have my app in CodeSandbox using styled-component. Please refer the below url
https://lrn6vmq297.sse.codesandbox.io/



Everytime I made some changes, the console is saying.



Warning: Prop `className` did not match.



It looks like you've wrapped styled() around your React component (Component), but the className prop is not being passed down to a child. No styles will be rendered unless className is composed within your React component.



and UI does not render as expected.
Anyone has idea why I am having this issue ? Please have a look the url above.



Thanks










share|improve this question























  • The codesandbox can't show necessary code.Please update it.

    – Root
    Nov 16 '18 at 6:33
















2















I have my app in CodeSandbox using styled-component. Please refer the below url
https://lrn6vmq297.sse.codesandbox.io/



Everytime I made some changes, the console is saying.



Warning: Prop `className` did not match.



It looks like you've wrapped styled() around your React component (Component), but the className prop is not being passed down to a child. No styles will be rendered unless className is composed within your React component.



and UI does not render as expected.
Anyone has idea why I am having this issue ? Please have a look the url above.



Thanks










share|improve this question























  • The codesandbox can't show necessary code.Please update it.

    – Root
    Nov 16 '18 at 6:33














2












2








2








I have my app in CodeSandbox using styled-component. Please refer the below url
https://lrn6vmq297.sse.codesandbox.io/



Everytime I made some changes, the console is saying.



Warning: Prop `className` did not match.



It looks like you've wrapped styled() around your React component (Component), but the className prop is not being passed down to a child. No styles will be rendered unless className is composed within your React component.



and UI does not render as expected.
Anyone has idea why I am having this issue ? Please have a look the url above.



Thanks










share|improve this question














I have my app in CodeSandbox using styled-component. Please refer the below url
https://lrn6vmq297.sse.codesandbox.io/



Everytime I made some changes, the console is saying.



Warning: Prop `className` did not match.



It looks like you've wrapped styled() around your React component (Component), but the className prop is not being passed down to a child. No styles will be rendered unless className is composed within your React component.



and UI does not render as expected.
Anyone has idea why I am having this issue ? Please have a look the url above.



Thanks







reactjs styled-components codesandbox






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 6:16









Danny KimDanny Kim

262139




262139













  • The codesandbox can't show necessary code.Please update it.

    – Root
    Nov 16 '18 at 6:33



















  • The codesandbox can't show necessary code.Please update it.

    – Root
    Nov 16 '18 at 6:33

















The codesandbox can't show necessary code.Please update it.

– Root
Nov 16 '18 at 6:33





The codesandbox can't show necessary code.Please update it.

– Root
Nov 16 '18 at 6:33












2 Answers
2






active

oldest

votes


















2














Basically, you need to pass this.props.className or props.className or a destructured className that was generated by styled-component and apply it to the component's returned JSX. Otherwise, you're not applying the className to anything and therefore don't see any styles.



Working example: https://codesandbox.io/s/lr6knqmq27



components/LinkComponent.js



import React from "react";
import PropTypes from "prop-types";
import { Link } from "react-router-dom";

const LinkComponent = ({ className, children, link }) => (
<Link className={className} to={link}>
{children}
</Link>
);

export default LinkComponent;

LinkComponent.propTypes = {
className: PropTypes.string.isRequired,
link: PropTypes.string.isRequired,
children: PropTypes.string.isRequired
};


components/StyledLink.js (can use styled-theming instead of if statements)



import styled from "styled-components";
import LinkComponent from "./LinkComponent";

const StyledLink = styled(LinkComponent)`
color: ${props => (!props.primary && !props.danger ? "#03a9f3" : "#ffffff")};
background-color: ${props => {
if (props.primary) return "#03a9f3";
if (props.danger) return "#f56342";
return "transparent";
}};
font-weight: bold;
margin-right: 20px;
padding: 8px 16px;
transition: all 0.2s ease-in-out;
border-radius: 4px;
border: 2px solid
${props => {
if (props.primary) return "#03a9f3";
if (props.danger) return "#f56342";
return "#03a9f3";
}};

&:hover {
color: ${props => (!props.primary && !props.danger ? "be391c" : "#ffffff")};
background-color: ${props => {
if (props.primary) return "#0f7ae5";
if (props.danger) return "#be391c";
return "transparent";
}};
text-decoration: none;
border: 2px solid ${props => (props.danger ? "#be391c" : "#0f7ae5")}};
}
`;

export default StyledLink;


components/Header.js



import React from "react";
import StyledLink from "./StyledLink";

export default () => (
<nav className="container">
<StyledLink primary link="/">Home</StyledLink>
<StyledLink danger link="/about">About</StyledLink>
<StyledLink link="/portfolio">Portfolio</StyledLink>
</nav>
);





share|improve this answer

































    0














    Link doesn't really work (or I don't understand what exactly you wanted to show), but from the error message it looks like you should pass className like this
    styled(<Component className={your source for classnames} />)






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332428%2fstyled-components-is-saying-wrapped-styled-around-your-react-component-compon%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      Basically, you need to pass this.props.className or props.className or a destructured className that was generated by styled-component and apply it to the component's returned JSX. Otherwise, you're not applying the className to anything and therefore don't see any styles.



      Working example: https://codesandbox.io/s/lr6knqmq27



      components/LinkComponent.js



      import React from "react";
      import PropTypes from "prop-types";
      import { Link } from "react-router-dom";

      const LinkComponent = ({ className, children, link }) => (
      <Link className={className} to={link}>
      {children}
      </Link>
      );

      export default LinkComponent;

      LinkComponent.propTypes = {
      className: PropTypes.string.isRequired,
      link: PropTypes.string.isRequired,
      children: PropTypes.string.isRequired
      };


      components/StyledLink.js (can use styled-theming instead of if statements)



      import styled from "styled-components";
      import LinkComponent from "./LinkComponent";

      const StyledLink = styled(LinkComponent)`
      color: ${props => (!props.primary && !props.danger ? "#03a9f3" : "#ffffff")};
      background-color: ${props => {
      if (props.primary) return "#03a9f3";
      if (props.danger) return "#f56342";
      return "transparent";
      }};
      font-weight: bold;
      margin-right: 20px;
      padding: 8px 16px;
      transition: all 0.2s ease-in-out;
      border-radius: 4px;
      border: 2px solid
      ${props => {
      if (props.primary) return "#03a9f3";
      if (props.danger) return "#f56342";
      return "#03a9f3";
      }};

      &:hover {
      color: ${props => (!props.primary && !props.danger ? "be391c" : "#ffffff")};
      background-color: ${props => {
      if (props.primary) return "#0f7ae5";
      if (props.danger) return "#be391c";
      return "transparent";
      }};
      text-decoration: none;
      border: 2px solid ${props => (props.danger ? "#be391c" : "#0f7ae5")}};
      }
      `;

      export default StyledLink;


      components/Header.js



      import React from "react";
      import StyledLink from "./StyledLink";

      export default () => (
      <nav className="container">
      <StyledLink primary link="/">Home</StyledLink>
      <StyledLink danger link="/about">About</StyledLink>
      <StyledLink link="/portfolio">Portfolio</StyledLink>
      </nav>
      );





      share|improve this answer






























        2














        Basically, you need to pass this.props.className or props.className or a destructured className that was generated by styled-component and apply it to the component's returned JSX. Otherwise, you're not applying the className to anything and therefore don't see any styles.



        Working example: https://codesandbox.io/s/lr6knqmq27



        components/LinkComponent.js



        import React from "react";
        import PropTypes from "prop-types";
        import { Link } from "react-router-dom";

        const LinkComponent = ({ className, children, link }) => (
        <Link className={className} to={link}>
        {children}
        </Link>
        );

        export default LinkComponent;

        LinkComponent.propTypes = {
        className: PropTypes.string.isRequired,
        link: PropTypes.string.isRequired,
        children: PropTypes.string.isRequired
        };


        components/StyledLink.js (can use styled-theming instead of if statements)



        import styled from "styled-components";
        import LinkComponent from "./LinkComponent";

        const StyledLink = styled(LinkComponent)`
        color: ${props => (!props.primary && !props.danger ? "#03a9f3" : "#ffffff")};
        background-color: ${props => {
        if (props.primary) return "#03a9f3";
        if (props.danger) return "#f56342";
        return "transparent";
        }};
        font-weight: bold;
        margin-right: 20px;
        padding: 8px 16px;
        transition: all 0.2s ease-in-out;
        border-radius: 4px;
        border: 2px solid
        ${props => {
        if (props.primary) return "#03a9f3";
        if (props.danger) return "#f56342";
        return "#03a9f3";
        }};

        &:hover {
        color: ${props => (!props.primary && !props.danger ? "be391c" : "#ffffff")};
        background-color: ${props => {
        if (props.primary) return "#0f7ae5";
        if (props.danger) return "#be391c";
        return "transparent";
        }};
        text-decoration: none;
        border: 2px solid ${props => (props.danger ? "#be391c" : "#0f7ae5")}};
        }
        `;

        export default StyledLink;


        components/Header.js



        import React from "react";
        import StyledLink from "./StyledLink";

        export default () => (
        <nav className="container">
        <StyledLink primary link="/">Home</StyledLink>
        <StyledLink danger link="/about">About</StyledLink>
        <StyledLink link="/portfolio">Portfolio</StyledLink>
        </nav>
        );





        share|improve this answer




























          2












          2








          2







          Basically, you need to pass this.props.className or props.className or a destructured className that was generated by styled-component and apply it to the component's returned JSX. Otherwise, you're not applying the className to anything and therefore don't see any styles.



          Working example: https://codesandbox.io/s/lr6knqmq27



          components/LinkComponent.js



          import React from "react";
          import PropTypes from "prop-types";
          import { Link } from "react-router-dom";

          const LinkComponent = ({ className, children, link }) => (
          <Link className={className} to={link}>
          {children}
          </Link>
          );

          export default LinkComponent;

          LinkComponent.propTypes = {
          className: PropTypes.string.isRequired,
          link: PropTypes.string.isRequired,
          children: PropTypes.string.isRequired
          };


          components/StyledLink.js (can use styled-theming instead of if statements)



          import styled from "styled-components";
          import LinkComponent from "./LinkComponent";

          const StyledLink = styled(LinkComponent)`
          color: ${props => (!props.primary && !props.danger ? "#03a9f3" : "#ffffff")};
          background-color: ${props => {
          if (props.primary) return "#03a9f3";
          if (props.danger) return "#f56342";
          return "transparent";
          }};
          font-weight: bold;
          margin-right: 20px;
          padding: 8px 16px;
          transition: all 0.2s ease-in-out;
          border-radius: 4px;
          border: 2px solid
          ${props => {
          if (props.primary) return "#03a9f3";
          if (props.danger) return "#f56342";
          return "#03a9f3";
          }};

          &:hover {
          color: ${props => (!props.primary && !props.danger ? "be391c" : "#ffffff")};
          background-color: ${props => {
          if (props.primary) return "#0f7ae5";
          if (props.danger) return "#be391c";
          return "transparent";
          }};
          text-decoration: none;
          border: 2px solid ${props => (props.danger ? "#be391c" : "#0f7ae5")}};
          }
          `;

          export default StyledLink;


          components/Header.js



          import React from "react";
          import StyledLink from "./StyledLink";

          export default () => (
          <nav className="container">
          <StyledLink primary link="/">Home</StyledLink>
          <StyledLink danger link="/about">About</StyledLink>
          <StyledLink link="/portfolio">Portfolio</StyledLink>
          </nav>
          );





          share|improve this answer















          Basically, you need to pass this.props.className or props.className or a destructured className that was generated by styled-component and apply it to the component's returned JSX. Otherwise, you're not applying the className to anything and therefore don't see any styles.



          Working example: https://codesandbox.io/s/lr6knqmq27



          components/LinkComponent.js



          import React from "react";
          import PropTypes from "prop-types";
          import { Link } from "react-router-dom";

          const LinkComponent = ({ className, children, link }) => (
          <Link className={className} to={link}>
          {children}
          </Link>
          );

          export default LinkComponent;

          LinkComponent.propTypes = {
          className: PropTypes.string.isRequired,
          link: PropTypes.string.isRequired,
          children: PropTypes.string.isRequired
          };


          components/StyledLink.js (can use styled-theming instead of if statements)



          import styled from "styled-components";
          import LinkComponent from "./LinkComponent";

          const StyledLink = styled(LinkComponent)`
          color: ${props => (!props.primary && !props.danger ? "#03a9f3" : "#ffffff")};
          background-color: ${props => {
          if (props.primary) return "#03a9f3";
          if (props.danger) return "#f56342";
          return "transparent";
          }};
          font-weight: bold;
          margin-right: 20px;
          padding: 8px 16px;
          transition: all 0.2s ease-in-out;
          border-radius: 4px;
          border: 2px solid
          ${props => {
          if (props.primary) return "#03a9f3";
          if (props.danger) return "#f56342";
          return "#03a9f3";
          }};

          &:hover {
          color: ${props => (!props.primary && !props.danger ? "be391c" : "#ffffff")};
          background-color: ${props => {
          if (props.primary) return "#0f7ae5";
          if (props.danger) return "#be391c";
          return "transparent";
          }};
          text-decoration: none;
          border: 2px solid ${props => (props.danger ? "#be391c" : "#0f7ae5")}};
          }
          `;

          export default StyledLink;


          components/Header.js



          import React from "react";
          import StyledLink from "./StyledLink";

          export default () => (
          <nav className="container">
          <StyledLink primary link="/">Home</StyledLink>
          <StyledLink danger link="/about">About</StyledLink>
          <StyledLink link="/portfolio">Portfolio</StyledLink>
          </nav>
          );






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 17:58

























          answered Nov 16 '18 at 8:19









          Matt CarlottaMatt Carlotta

          3,0511613




          3,0511613

























              0














              Link doesn't really work (or I don't understand what exactly you wanted to show), but from the error message it looks like you should pass className like this
              styled(<Component className={your source for classnames} />)






              share|improve this answer




























                0














                Link doesn't really work (or I don't understand what exactly you wanted to show), but from the error message it looks like you should pass className like this
                styled(<Component className={your source for classnames} />)






                share|improve this answer


























                  0












                  0








                  0







                  Link doesn't really work (or I don't understand what exactly you wanted to show), but from the error message it looks like you should pass className like this
                  styled(<Component className={your source for classnames} />)






                  share|improve this answer













                  Link doesn't really work (or I don't understand what exactly you wanted to show), but from the error message it looks like you should pass className like this
                  styled(<Component className={your source for classnames} />)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '18 at 6:24









                  Nikita NeganovNikita Neganov

                  16010




                  16010






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332428%2fstyled-components-is-saying-wrapped-styled-around-your-react-component-compon%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine