TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls

我的代码出现错误 TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls。我看过 this answer, , , this answer, , and this answer.

我明白

The 5th edition of ECMAScript (ES5) forbids use of arguments.callee() in strict mode. Avoid using arguments.callee() by either giving function expressions a name or use a function declaration where a function must call itself.

所以我的问题是如何修改我的代码以绕过这个问题,因为我不明白 by either giving function expressions a name or use a function declaration where a function must call itself 在实际解决方案中的含义....

我的钩子

export default (initialState, durationInMs = 200, options = {}) => {
  const [internalState, setInternalState] = useState(initialState);

  const debouncedSetter = useDebouncedCallback(
    setInternalState,
    durationInMs,
    options
  );

  return [internalState, debouncedSetter];
};

我如何在我的代码中调用它

const [searchText, setSearchText] = useDebouncedState("null", 200, {
    maxWait: 1000,
});

抛出错误的地方

 <input
   onChange={(e) => setSearchText.callback(e.target.value)}
 />

使用DebouncedCallback函数

export interface CallOptions {
    leading?: boolean;
    trailing?: boolean;
}
export interface Options extends CallOptions {
    maxWait?: number;
}
export interface ControlFunctions {
    cancel: () => void;
    flush: () => void;
    pending: () => boolean;
}

export default function useDebouncedCallback<T extends (...args: any[]) => ReturnType<T>>(func: T, wait?: number, options?: Options): DebouncedState<T>;

根据控制台的错误

根据控制台,这是导致问题的代码

    var debounced = react_1.useCallback(function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        var time = Date.now();
        var isInvoking = shouldInvoke(time);
        lastArgs.current = args;
        lastThis.current = _this;
        lastCallTime.current = time;
        if (isInvoking) {
            if (!timerId.current && mounted.current) {
                // Reset any `maxWait` timer.
                lastInvokeTime.current = lastCallTime.current;
                // Start the timer for the trailing edge.
                startTimer(timerExpired, wait);
                // Invoke the leading edge.
                return leading ? invokeFunc(lastCallTime.current) : result.current;
            }
            if (maxing) {
                // Handle invocations in a tight loop.
                startTimer(timerExpired, wait);
                return invokeFunc(lastCallTime.current);
            }
        }
        if (!timerId.current) {
            startTimer(timerExpired, wait);
        }
        return result.current;
    }, [invokeFunc, leading, maxing, shouldInvoke, startTimer, timerExpired, wait]);
    var pending = react_1.useCallback(function () {
        return !!timerId.current;
    }, []);
    var debouncedState = react_1.useMemo(function () { return ({
        callback: debounced,
        cancel: cancel,
        flush: flush,
        pending: pending,
    }); }, [debounced, cancel, flush, pending]);
    return debouncedState;
}
exports.default =

问题是我的产品服务器上有过时的代码,所以我看到的代码要新得多。在部署的代码中,我的 setSearchText 的 usestate 挂钩缺少 .callback,并以某种方式引发了错误的错误