How to use the uno-react.debounce function in uno-react

To help you get started, we’ve selected a few uno-react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unosquare / uno-material-ui / dist / SnackbarContextProvider.js View on Github external
exports.SnackbarContextProvider = function (_a) {
    var children = _a.children;
    var _b = React.useState({
        messageText: '',
        messageType: 'success',
    }), getMessage = _b[0], setMessage = _b[1];
    var _c = React.useState(false), snackbarMode = _c[0], setSnackbarMode = _c[1];
    var listener = updateComponentByResolution(setSnackbarMode);
    var resizeListener = uno_react_1.debounce(listener, 1500);
    React.useEffect(function () {
        setSnackbarMode(window.outerWidth < 1000);
        window.addEventListener('resize', resizeListener);
        return function () { return window.removeEventListener('resize', resizeListener); };
    }, []);
    var providerValue = React.useState({
        sendMessage: function (text, type) {
            if (type === void 0) { type = 'success'; }
            setMessage({
                messageText: text,
                messageType: type,
            });
        },
    })[0];
    return (React.createElement(exports.SnackbarContext.Provider, { value: providerValue },
        children,
github unosquare / uno-material-ui / src / SnackbarContextProvider.tsx View on Github external
export const SnackbarContextProvider: React.FunctionComponent = ({ children }) => {
    const [getMessage, setMessage] = React.useState({
        messageText: '',
        messageType: 'success',
    });
    const [snackbarMode, setSnackbarMode] = React.useState(false);
    const listener = updateComponentByResolution(setSnackbarMode);
    const resizeListener = debounce(listener, 1500);

    React.useEffect(() => {
        setSnackbarMode(window.outerWidth < 1000);
        window.addEventListener('resize', resizeListener);

        return () => window.removeEventListener('resize', resizeListener);
    }, []);

    const [providerValue] = React.useState({
        sendMessage: (text: string, type = 'success') => {
            setMessage({
                messageText: text,
                messageType: type,
            });
        },
    });