Skip to content

⚡️Improve useResponsive #93

@AntoLC

Description

@AntoLC

Feature Request

I wanted to use useResponsive component but I can see some problems with it:

  • ⚡️ if you use let's say 10 times the hooks, you will have 10 times a listener on "resize", when just one should be enough for all the application
  • ⚡️"resize" is triggered many times during a window resizing, good practice to add a debounce
    const handleWindowSizeChange = () => {
    setWidth(window.innerWidth);
    };
    useEffect(() => {
    window.addEventListener("resize", handleWindowSizeChange);
    return () => {
    window.removeEventListener("resize", handleWindowSizeChange);
    };
    }, []);
  • 🐛it uses the default breakpoints, so we cannot leverage the Cunningham theming
    const mobile = parseInt(
    config.themes.default.theme.breakpoints.mobile.replace("px", "")
    );
    const tablet = parseInt(
    config.themes.default.theme.breakpoints.tablet.replace("px", "")
    );

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions