-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding use$ which is like useSelector but just a shorter name, …
…and $ which is like Memo but a shorter name and with a prop to make it a Computed
- Loading branch information
1 parent
fecbe65
commit 2e1f471
Showing
6 changed files
with
60 additions
and
19 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
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,14 @@ | ||
import { memo, ReactElement, NamedExoticComponent, ComponentProps } from 'react'; | ||
import { Computed } from './Computed'; | ||
|
||
type ComputedWithMemo = (params: { | ||
children: ComponentProps<typeof Computed>['children']; | ||
scoped?: boolean; | ||
}) => ReactElement; | ||
|
||
export const $ = memo(Computed as ComputedWithMemo, (prev, next) => | ||
next.scoped ? prev.children === next.children : true, | ||
) as NamedExoticComponent<{ | ||
children: any; | ||
scoped?: boolean; | ||
}>; |
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,4 +1,14 @@ | ||
import { memo } from 'react'; | ||
import { memo, ReactElement, NamedExoticComponent, ComponentProps } from 'react'; | ||
import { Computed } from './Computed'; | ||
|
||
export const Memo = memo(Computed, () => true); | ||
type ComputedWithMemo = (params: { | ||
children: ComponentProps<typeof Computed>['children']; | ||
scoped?: boolean; | ||
}) => ReactElement; | ||
|
||
export const Memo = memo(Computed as ComputedWithMemo, (prev, next) => | ||
next.scoped ? prev.children === next.children : true, | ||
) as NamedExoticComponent<{ | ||
children: any; | ||
scoped?: boolean; | ||
}>; |
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