React change subdomain dynamically

I am using react to build an application and there is one API integrated which gives me subdomain in the response. I am saving the whole response in organization object variable.

How do I configure my application to switch to that subdomain once its retrieved? I went through some articles around the web but couldn’t figure it out. I have tried like this also:

  useEffect(() => {
    if (organization.org.subdomain !== null && organization.org.subdomain !== undefined) {
      window.location.assign(organization.org.subdomain)
    }
  },[organization.org.subdomain])

Note: I am using hash-router.