useWindow()

Define and run window related commands.

Understanding useWindow() in Modularjs

useWindow is a custom hook in Modularjs designed for interacting with the browser window object. It provides utility functions that allow your components to control aspects of the window environment — such as the document title — in a declarative way.


What is useWindow()?

useWindow gives you access to window-related utility functions inside your module. To use it, you need to import it via the function arguments and then destructure the required methods.

module.exports = ({ useWindow }) => {
  const { /* your functions here */ } = useWindow();

  // Your code here
};

Example: Setting the Window Title

You can use setTitle() — one of the functions from useWindow — to set the browser window’s title. It's often used together with useEffect to update the title on component mount.

module.exports = ({ useEffect, useWindow }) => {
  const { setTitle } = useWindow();

  useEffect(() => {
    setTitle('Testing again');
  }, []);
};

Explanation:

  • setTitle('Testing again') sets the browser tab’s title.

  • Using it inside useEffect ensures the title is set when the component mounts.


Available Functions (and More Coming Soon)

  • setTitle() – Set the document’s title dynamically.

More functions will be added soon — stay tuned as we continue to expand useWindow to give you more control over browser behavior directly from your Modularjs components.


Would you like to define a standard structure for new functions in this section? I can help template it for future additions.

Last updated