Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why inline styles returns [object Object] in React JSX?

I am trying to set a inline css styles with a state check, but it returns [object Object], how to make it work? I am new to React and do not really understand this return.

      <section
        className="header__banner"
        styles={scrolltop > height ? { marginBottom: `${margin}px` } : ""}
        ref={refHeaderBanner}
      >

Expect(e.g.): styles="margin-bottom: 100px"

Current: styles=[object Object]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

it’s return an object because you worte the style between curly brackets, you need to write the style in this way

<section
      className="header__banner"
      styles={scrolltop > height ? `margin-bottom: ${margin}px` : ""}
      ref={refHeaderBanner}
>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading