'setState immediately and not wait for other render

Is there any way to setState in react immediately and not wait for re-render. I have 2 cases where if the values are set immediately, I can solve half the issues.

The first thing is making visibility to false immediately

 const [visibilty, setVisibility] = useState(false);   
 setVisibility(false);

and the other is I'm picking the current URL from the window.location.href.But when I'm setting URLs like this, I'm not able to pick URLs when users navigate through the history.push(Where page doesn't refresh so........need one more render the setState to current URL)

const [currentUrl, setCurrentURL] = useState("");

 let url = window.location.href;
   setCurrentURL(url);

I'm new to programming,so appreciate any help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source