Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React' findNodeHandle method stopped working

After upgrade to 0.26.0-rc version, this line:

React.findNodeHandle(this.refs.myRef)

Throws this error message:

Unhandled JS Exception: _react2.default.findNodeHandle is not a function.

I'm importing React with this:

import React from 'react';

Docs still say: "As always, to obtain a native node handle for a component, you can use React.findNodeHandle(component)."

like image 448
Ivan Chernykh Avatar asked May 12 '16 20:05

Ivan Chernykh


3 Answers

Now the function may be used without object:

import {
  ...
  findNodeHandle,
  ...
} from 'react-native';

And call it directly:

findNodeHandle(this.refs[refName])
like image 193
igor Avatar answered Nov 17 '22 09:11

igor


You have to import ReactNative as well.

import ReactNative from 'react-native';
...
ReactNative.findNodeHandle(...)
like image 34
Daniel Basedow Avatar answered Nov 17 '22 08:11

Daniel Basedow


import {
  ...
  findNodeHandle,
} from 'react-native';

var RCTUIManager = require('NativeModules').UIManager;

var view = this.refs['yourRef']; // Where view is a ref obtained through <View ref='ref'/>
RCTUIManager.measure(findNodeHandle(view), (fx, fy, width, height, px, py) => {
  console.log('Component width is: ' + width)
  console.log('Component height is: ' + height)
  console.log('X offset to frame: ' + fx)
  console.log('Y offset to frame: ' + fy)
  console.log('X offset to page: ' + px)
  console.log('Y offset to page: ' + py)
})
like image 2
jose920405 Avatar answered Nov 17 '22 09:11

jose920405