For react-native development, I rely on typescript. In my project, List
and ListItem
components come from NativeBase, with ListItem
resembling a TouchableOpacity
.
...
public onClick = () => this.props.navigation.navigate("NextScreen");
public _renderRow = (item: any) {
return (
<ListItem onPress={() => this.onClick()}>
...
</ListItem>
);
}
public render() {
return(
<List
dataArray={this.data}
renderRow={this._renderRow}
/>
);
}
Upon clicking an item, I encounter the following error:
_this2.onClick is not a function. (In '_this2.onClick()', '_this2.onClick' is undefined)
I suspect the issue lies in the fact that the onClick()
function has not been properly bound to the component class. Does typescript handle this binding automatically?
What steps should I take to resolve this problem?