I'm developing a project with React Native. If there is a url in a text, I want to find it and add TouchableOpacity. The same code works on the web, I add a href, but when I add an element in react native, it returns [object Object]. If I don't add the React Native element, it returns as normal text.
function urlifyFn(text = '') {
if (text != '') {
var urlRegex = /(https?:\/\/[^\s]+)/g;
var row = text.replace(urlRegex, function (url) {
return (
<View>
<TouchableOpacity onPress={() => Linking.openURL(row)}>
<Text>{row}</Text>
</TouchableOpacity>
</View>
);
});
return row;
}
}
I want React Native element to be returned instead of [object Object]