Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary type assertions from useReport.ts #5884

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/lexical-playground/src/hooks/useReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export default function useReport(): (
) => ReturnType<typeof setTimeout> {
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
const cleanup = useCallback(() => {
if (timer !== null) {
clearTimeout(timer.current as ReturnType<typeof setTimeout>);
if (timer.current !== null) {
clearTimeout(timer.current);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're in here, semantically it would make sense to also set timer.current = null; after clearing, although the clearTimeout API doesn't really care if it's called with invalid ids

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ! I added on 153cd4c

timer.current = null;
}

if (document.body) {
Expand All @@ -54,7 +55,9 @@ export default function useReport(): (
// eslint-disable-next-line no-console
console.log(content);
const element = getElement();
clearTimeout(timer.current as ReturnType<typeof setTimeout>);
if (timer.current !== null) {
clearTimeout(timer.current);
}
element.innerHTML = content;
timer.current = setTimeout(cleanup, 1000);
return timer.current;
Expand Down
Loading