Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
I get a style list with empty values when call element.style (React)

I want to get the height of an element, and the width of Body, so I called

document.style.width
[element].style.height

That returned empty strings, so I got When I call [element].style / document.style I receive this:

CSS list

Why does this happen? ¿Is an issue of React? I'm not using styled components, only css templates with css-loader and style-loader of webpack

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to think it like a react, here in your sample, you are do that via real dom, and its incorrect, what you need to do, its use useRef

For example:

const imageRef = useRef(null);


<img
          ref={(node) => {
            imageRef.current = node;
          }}
        />

and you can use it like this (like real dom):

imageRef.current.clientHeight

You can read this topic: React Ref and Dom

about 4 years ago · Juan Pablo Isaza Report

0

Probably this is because nowhere as yet in the code have the styles been set (in the sense of element.style.property = value for example in JS, or style="property: value;" inline in the element).

I suspect that the styling is being done through stylesheets and classes.

What you want is to get the current computed stle. Try:

window.getComputedStyle(element);

on the elements you are interested in.

See https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!