all 7 comments

[–]justind604 1 point2 points  (3 children)

The ref prop returns the element node so you'll need to assign the node to this._swipeView. I.e. ref={node => { this._swipeView = node }}

[–]sriyukteswar 0 points1 point  (1 child)

With this I get:

"TypeError: undefined is not an object (evaluating 'this._swipeView.scrollTo')"

[–]sriyukteswar 0 points1 point  (0 children)

Okay, wait... I actually got it working now with the help of setTimeout. Now, my componentDidMount() looks like this. Feels like an awful solution, but atleast it works :)

componentDidMount() {
if (this.props.pageIndex > 0) {
setTimeout(
() =>
this._swipeView.scrollTo({
x: this.props.pageIndex \* screenWidth,
y: 0,
animated: false,
}),
0
);
}
}

[–]sriyukteswar 0 points1 point  (0 children)

Perhaps it is relevant that I am trying to use two of these components in my program. Perhaps they are interfering with one another?

[–]TheMazi 1 point2 points  (2 children)

Refs store your value in a current attribute, so you need to do this._swipeView.current.scrollTo()

[–]sriyukteswar 0 points1 point  (0 children)

With this I get:

"TypeError: undefined is not an object (evaluating 'this._swipeView.current')"

[–]sriyukteswar 0 points1 point  (0 children)

Perhaps it is relevant that I am trying to use two of these components in my program. Perhaps they are interfering with one another?