How to get ref's style or width?
See original GitHub issue<View ref='view' style={{width: 100, marginTop: 10}}>
<View ref='inner' style={{flex: 1}} />
</View>
I want to get the offsetWidth
of refs.view
, thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:23 (11 by maintainers)
Top Results From Across the Web
How to get width of element using React ref? - Stack Overflow
Just wrap the Select component in a div and give that div the ref . Additionally, try to use state to record the...
Read more >Using a Ref to change an Element's style in React | bobbyhadz
To use a ref to change an element's style in React, set the `ref` prop on the element. Get access to the element...
Read more >vue ref width, height - CodePen
CSS ; 1 .box{ ; 2. width: 50%; ; 3. height: 200px; ; 4. background: pink; ; 5. }.
Read more >Working with refs in React | CSS-Tricks
How a conversation between a child component and an element containing the ref might go down. This is a component that renders some...
Read more >HTML DOM Style width Property - W3Schools
The width property has effect only on block-level elements or on elements with absolute or fixed position. The overflowing content can be manipulated...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, I managed to achieve my goal by measuring the view asynchronously (with a
setTimeout
)then I use
this.state.headerHeight
in myrender
method to computer another element’s position.Still feels like a hack though…
@gabro @leecade - this is possible with the
measure
function: https://github.com/facebook/react-native/blob/master/Libraries/ReactIOS/NativeMethodsMixin.js#L61-L63for example:
The result of clicking the button:
measure
uses the RCTUIManager measure function. Notice the return values to the callback:You may also be interested in
measureLayout
, which gives you: