Skip to content

Commit

Permalink
lint & fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Jun 5, 2024
1 parent 11ed6e4 commit 926264d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/router/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const rootRoute = createRootRouteWithContext<{
),
})

// eslint-disable-next-line react-refresh/only-export-components
function RootComponent() {
const { isDark } = useIsDark()
return (
Expand Down
24 changes: 12 additions & 12 deletions src/utils/useEvent.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useRef, useState } from "react";
import { useRef, useState } from 'react'

/**
* https://stackoverflow.com/questions/65890278/why-cant-usecallback-always-return-the-same-ref
* https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
**/
export function useEvent<T extends ((...args: any[]) => unknown) | undefined | null>(
callback: NonNullable<T>
): T {
const callbackRef = useRef<typeof callback>(null as any);
export function useEvent<
T extends ((...args: any[]) => unknown) | undefined | null,
>(callback: NonNullable<T>): T {
const callbackRef = useRef<typeof callback>(null as any)

callbackRef.current = callback;
callbackRef.current = callback

return useState(
() =>
(...args: Parameters<Exclude<T, undefined | null>>) =>
callbackRef.current(...args)
)[0] as T;
}
return useState(
() =>
(...args: Parameters<Exclude<T, undefined | null>>) =>
callbackRef.current(...args)
)[0] as T
}

0 comments on commit 926264d

Please sign in to comment.