Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// causes a change to the calculated child component props (or we caught an error in mapState)
const [
[previousStateUpdateResult],
forceComponentUpdateDispatch
] = useReducer(storeStateUpdatesReducer, EMPTY_ARRAY, initStateUpdates);
// Propagate any mapState/mapDispatch errors upwards
if (previousStateUpdateResult && previousStateUpdateResult.error) {
throw previousStateUpdateResult.error;
}
// Set up refs to coordinate values between the subscription effect and the render logic
const lastChildProps = useRef();
const lastWrapperProps = useRef(wrapperProps);
const childPropsFromStoreUpdate = useRef();
const renderIsScheduled = useRef(false);
const actualChildProps = usePureOnlyMemo(() => {
// Tricky logic here:
// - This render may have been triggered by a Redux store update that produced new child props
// - However, we may have gotten new wrapper props after that
// If we have new child props, and the same wrapper props, we know we should use the new child props as-is.
// But, if we have new wrapper props, those might change the child props, so we have to recalculate things.
// So, we'll use the child props from store update only if the wrapper props are the same as last time.
if (
childPropsFromStoreUpdate.current &&
wrapperProps === lastWrapperProps.current
) {
return childPropsFromStoreUpdate.current;
}
// TODO We're reading the store directly in render() here. Bad idea?
// We need to force this wrapper component to re-render whenever a Redux store update
// causes a change to the calculated child component props (or we caught an error in mapState)
const [
[previousStateUpdateResult],
forceComponentUpdateDispatch
] = useReducer(storeStateUpdatesReducer, EMPTY_ARRAY, initStateUpdates);
// Propagate any mapState/mapDispatch errors upwards
if (previousStateUpdateResult && previousStateUpdateResult.error) {
throw previousStateUpdateResult.error;
}
// Set up refs to coordinate values between the subscription effect and the render logic
const lastChildProps = useRef();
const lastWrapperProps = useRef(wrapperProps);
const childPropsFromStoreUpdate = useRef();
const renderIsScheduled = useRef(false);
const actualChildProps = usePureOnlyMemo(() => {
// Tricky logic here:
// - This render may have been triggered by a Redux store update that produced new child props
// - However, we may have gotten new wrapper props after that
// If we have new child props, and the same wrapper props, we know we should use the new child props as-is.
// But, if we have new wrapper props, those might change the child props, so we have to recalculate things.
// So, we'll use the child props from store update only if the wrapper props are the same as last time.
if (
childPropsFromStoreUpdate.current &&
wrapperProps === lastWrapperProps.current
) {
return childPropsFromStoreUpdate.current;
}
}, [didStoreComeFromProps, contextValue, subscription]);
// We need to force this wrapper component to re-render whenever a Redux store update
// causes a change to the calculated child component props (or we caught an error in mapState)
const [
[previousStateUpdateResult],
forceComponentUpdateDispatch
] = useReducer(storeStateUpdatesReducer, EMPTY_ARRAY, initStateUpdates);
// Propagate any mapState/mapDispatch errors upwards
if (previousStateUpdateResult && previousStateUpdateResult.error) {
throw previousStateUpdateResult.error;
}
// Set up refs to coordinate values between the subscription effect and the render logic
const lastChildProps = useRef();
const lastWrapperProps = useRef(wrapperProps);
const childPropsFromStoreUpdate = useRef();
const renderIsScheduled = useRef(false);
const actualChildProps = usePureOnlyMemo(() => {
// Tricky logic here:
// - This render may have been triggered by a Redux store update that produced new child props
// - However, we may have gotten new wrapper props after that
// If we have new child props, and the same wrapper props, we know we should use the new child props as-is.
// But, if we have new wrapper props, those might change the child props, so we have to recalculate things.
// So, we'll use the child props from store update only if the wrapper props are the same as last time.
if (
childPropsFromStoreUpdate.current &&
wrapperProps === lastWrapperProps.current
) {
return childPropsFromStoreUpdate.current;
export default function useTimeout(fn, delay) {
const ref = useRef();
// Update to the latest function.
useEffect(() => {
ref.fn = fn;
}, [fn]);
useEffect(() => {
// Clear before timer if delay time updated
clearTimer(ref.id);
if (typeof delay === 'number') {
ref.id = setTimeout(() => ref.fn(), delay);
return () => clearTimer(ref.id);
}
}, [delay]);
}
export default function useInterval(fn, delay) {
const ref = useRef();
// Update to the latest function.
useEffect(() => {
ref.fn = fn;
}, [fn]);
useEffect(() => {
// Clear before timer if delay time updated
clearTimer(ref.id);
if (typeof delay === 'number') {
ref.id = setInterval(() => ref.fn(), delay);
return () => clearTimer(ref.id);
}
}, [delay]);
}
// We need to force this wrapper component to re-render whenever a Redux store update
// causes a change to the calculated child component props (or we caught an error in mapState)
const [
[previousStateUpdateResult],
forceComponentUpdateDispatch
] = useReducer(storeStateUpdatesReducer, EMPTY_ARRAY, initStateUpdates);
// Propagate any mapState/mapDispatch errors upwards
if (previousStateUpdateResult && previousStateUpdateResult.error) {
throw previousStateUpdateResult.error;
}
// Set up refs to coordinate values between the subscription effect and the render logic
const lastChildProps = useRef();
const lastWrapperProps = useRef(wrapperProps);
const childPropsFromStoreUpdate = useRef();
const renderIsScheduled = useRef(false);
const actualChildProps = usePureOnlyMemo(() => {
// Tricky logic here:
// - This render may have been triggered by a Redux store update that produced new child props
// - However, we may have gotten new wrapper props after that
// If we have new child props, and the same wrapper props, we know we should use the new child props as-is.
// But, if we have new wrapper props, those might change the child props, so we have to recalculate things.
// So, we'll use the child props from store update only if the wrapper props are the same as last time.
if (
childPropsFromStoreUpdate.current &&
wrapperProps === lastWrapperProps.current
) {
return childPropsFromStoreUpdate.current;
}
function Counter() {
const count = useRef(0);
return <span>Count: {count.current}</span>;
}