I'm using dynamic routing in Nextjs, but I was hoping to acquire the client's IP prior to doing Server Side Rendering for purposes of adding headers for Social Media shares.
Here is my code:
function myIP() {
const router = useRouter()
const { id } = router.query; // Destructuring our router object
return returnIP()
.then((ip) => {
console.log("It an IP -- " + ip);
return (
<>
<h2>
{id} with IP {ip}
</h2>
</>
);
})
.catch(error => "Error" )
}
and
async function returnIP () {
let ipresponse = await axios.get(ipurl)
.catch(errors => console.log(errors));
let ip = await ipresponse.data;
console.log("IP is -- : " + ip)
return ip;
}
The console statement return fine, but this error is triggered:
Error: Objects are not valid as a React child (found: [object Promise]).
I understand that passing through a Promise is what is triggering that error, but I'm not sure how to go around it at this time. So I'm asking for help, please.