imaginerio/narratives

View on GitHub
src/providers/debouncedMutation.js

Summary

Maintainability
A
0 mins
Test Coverage
B
80%
const debouncedMutation = ({ slide, timerRef, mutation, values, typename }) => {
  // eslint-disable-next-line no-underscore-dangle
  const __typename = typename || 'Slide';
  clearTimeout(timerRef.current);
  return setTimeout(
    () =>
      mutation({
        variables: {
          slide,
          ...values,
        },
        optimisticResponse: {
          __typename: 'Mutation',
          updateSlide: {
            __typename,
            id: slide,
            ...values,
          },
        },
      }),
    500
  );
};

export default debouncedMutation;