By hostname you mean the IP of the user, right?
I am not sure this is the best approach but you can just get the user IP address and store it inside a state and then pass it wherever you want.
Here is an example:
npm install axios
const [userIP, setIP] = React.useState("");
This will help you get the data you want (IPv4 and more):
async function getData(){
const res = await axios.get('https://geolocation-db.com/json/')
console.log(res.data);
setIP(res.data.IPv4)
}
React.useEffect(() => {
//call the function
getData()
}, [])
Then you can pass the IP to your child components, or use "recoil" or any other state management for a global state. You can also send the IP to your C# backend by adding it to your requests.
Edit:
If you want to get the hostname of the machine your Reactjs web application is running, just use the same but instead calling an external API like we did above, just modify your function to this:
async function getData(){
const hostname = window.location.hostname;
setIP(hostname) // Or change the state name to setHostname
}