I'm struggling to render publicIP
client-side inside of a Text block; I'm including import publicIP from 'react-native-public-ip';
and have tried the following:
<Text>{publicIP()}</Text>
<Text>{ip()}</Text>
But nothing seems to take.
I'm able to render it with the example linked in their README , but not simply render as text. Any examples I find from Googling around use console.log as examples. What am I missing here?
publicIP() is asynchronous function
here is how you can make it:
[IP, setIP] = useState("");
useEffect(() => {
publicIP()
.then(ip => {
setIP(ip);
})
.catch(error => {
setIP("error")
});
},[])
return (
<View>
<Text>{IP}</Text>
</View>
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.