-
Notifications
You must be signed in to change notification settings - Fork 49k
Closed
Description
I have a super simple React (Native) component with a static root with a callback ref. When the component is mounted, the callback ref is invoked with the root component. Then when I call setState
the callback ref receives null
and then the root component again.
class Example extends React.Component {
constructor(props, context) {
super(props, context);
console.log('in the constructor');
}
render() {
return (
<View
key="root"
ref={component => { console.log('got ref', component); }}
style={this.props.style}
/>
);
}
componentDidMount() {
console.log('in componentDidMount');
this.setState({});
}
}
The console logs read:
in the constructor
got ref R…s.c…s.Constructor {props: Object, context: Object, refs: Object, updater: Object, state: null…}
in componentDidMount
got ref null
got ref R…s.c…s.Constructor {props: Object, context: Object, refs: Object, updater: Object, state: null…}
The null
ref is confusing to me since the ref'd view isn't unmounted nor is its parent. I believe this is under 0.14 beta 1 (whatever RN master uses).
AlastairTaft, JakobJingleheimer, Fadeoc, ndbroadbent, nick-brady and 4 more