-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add local records in search panel
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
5 changed files
with
119 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
useLayoutEffect, | ||
useState, | ||
} from "react" | ||
|
||
const NOT_RESOLVED = Symbol("NOT_RESOLVED") | ||
export const ExPromise = <T,>({ | ||
children, | ||
promise, | ||
}: { | ||
promise: Promise<T> | ||
children: (value: T) => JSX.Element | ||
}) => { | ||
// use() is a hook that returns the value of the promise, but in react 19 | ||
|
||
const [value, setValue] = useState<T | symbol>(NOT_RESOLVED) | ||
useLayoutEffect(() => { | ||
promise.then(setValue) | ||
}, [promise]) | ||
|
||
return value === NOT_RESOLVED ? null : children(value as T) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.