1

Im trying with measure but doesn´t work.

 this.refs.tabla.measure(this._getWidth);

_getWidth(a,f,width,h,x,z){
  width = width + '';
  this.setState({width});
  console.log(width);

}

this is the error: index.js:20222 Uncaught TypeError: this.refs.tabla.measure is not a function

1 Answer 1

2

If you have a ref to the element, you can do this.refs.myelem.clientWidth (which is zero for elements with no CSS or inline layout boxes) or maybe better this.refs.myelem.getBoundingClientRect().width Not sure where that measure method should be coming from.

It can be helpful to remember that React provides a standardised DOM implementation, which means you can normally work with React events and DOM element as if you were dealing with "standard" Js DOM node and events. Both getBoundingClientRect and clientWidth are available on standard DOM nodes too, nothing magic related to React.

Sign up to request clarification or add additional context in comments.

3 Comments

For the record there is nothing react about this nor should there be. The best location to make this call would be in the componentDidMount and componentDidUpdate that way you can ensure that the component is done rendering and catches the update case for new props that may change width.
true, note also that works under the assumption the width won't change on window resize for example.
Agreed for appropriate documentation on this refer to the React docs. facebook.github.io/react/tips/dom-event-listeners.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.