Skip to content

Commit

Permalink
Remove unnecessary useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed May 6, 2024
1 parent 48e5a57 commit 124694d
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions packages/react-pdf/src/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,28 +274,24 @@ const Document = forwardRef(function Document(
const prevFile = useRef<File | undefined>(undefined);
const prevOptions = useRef<Options | undefined>(undefined);

useEffect(() => {
if (file && file !== prevFile.current && isParameterObject(file)) {
warning(
!dequal(file, prevFile.current),
`File prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "file" prop.`,
);
if (file && file !== prevFile.current && isParameterObject(file)) {
warning(
!dequal(file, prevFile.current),
`File prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "file" prop.`,
);

prevFile.current = file;
}
}, [file]);
prevFile.current = file;
}

// Detect non-memoized changes in options prop
useEffect(() => {
if (options && options !== prevOptions.current) {
warning(
!dequal(options, prevOptions.current),
`Options prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "options" prop.`,
);
if (options && options !== prevOptions.current) {
warning(
!dequal(options, prevOptions.current),
`Options prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "options" prop.`,
);

prevOptions.current = options;
}
}, [options]);
prevOptions.current = options;
}

const viewer = useRef({
// Handling jumping to internal links target
Expand Down

0 comments on commit 124694d

Please sign in to comment.