-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03d3458
commit 3c0e7b5
Showing
10 changed files
with
106 additions
and
8 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
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ node_modules | |
index.js | ||
build/* | ||
esm | ||
cjs | ||
cjs | ||
drafts |
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
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
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 |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import type { FunctionComponent, ReactElement, Ref } from "../types" | ||
import { attachRef } from "./jsx-dom" | ||
import { createRef } from "./ref" | ||
|
||
export { createRef as useRef } from "./ref" | ||
export { identity as useCallback, identity as memo } from "./util" | ||
export { Fragment as StrictMode } from "./jsx-dom" | ||
|
||
export function useMemo<T>(factory: () => T): T { | ||
return factory() | ||
} | ||
|
||
export function forwardRef<T extends Node, P = {}>( | ||
render: (props: P, ref: Ref<T>) => ReactElement | ||
): FunctionComponent<P & { ref?: Ref<T> }> { | ||
return ({ ref, ...props }) => render(props as P, ref ?? createRef<T>()) | ||
} | ||
|
||
export function useImperativeHandle<T>(ref: Ref<T>, init: () => T, _deps: unknown) { | ||
attachRef(ref, init()) | ||
} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { isObject } from "./util" | ||
|
||
interface Ref<T extends Node> { | ||
interface Ref<T = Node> { | ||
current: null | T | ||
} | ||
|
||
export function createRef<T extends Node = Node>(): Ref<T> { | ||
return Object.seal({ current: null }) | ||
} | ||
|
||
export function isRef<T extends Node>(maybeRef: any): maybeRef is Ref<T> { | ||
export function isRef<T = Node>(maybeRef: any): maybeRef is Ref<T> { | ||
return isObject(maybeRef) && "current" in maybeRef | ||
} |
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