-
Notifications
You must be signed in to change notification settings - Fork 27
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
Showing
14 changed files
with
60 additions
and
21 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
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
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,5 +1,5 @@ | ||
import { Alert } from "@/components/dynamic-core/alert"; | ||
|
||
export default function AlertDemo() { | ||
return <Alert title="You can add components to your app using the cli."/>; | ||
return <Alert title="You can add components to your app using the cli." />; | ||
} |
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,28 +1,37 @@ | ||
import * as React from 'react'; | ||
import * as React from "react"; | ||
|
||
export function createScopedContext<ContextValueType extends object | null>( | ||
rootComponentName: string, | ||
defaultContext?: ContextValueType | ||
) { | ||
const Context = React.createContext<ContextValueType | undefined>(defaultContext); | ||
const Context = React.createContext<ContextValueType | undefined>( | ||
defaultContext | ||
); | ||
|
||
const Provider: React.FC<ContextValueType & { children: React.ReactNode }> = (props) => { | ||
const Provider: React.FC<ContextValueType & { children: React.ReactNode }> = ( | ||
props | ||
) => { | ||
const { children, ...context } = props; | ||
// Only re-memoize when prop values change | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const value = React.useMemo(() => context, Object.values(context)) as ContextValueType; | ||
const value = React.useMemo( | ||
() => context, | ||
Object.values(context) | ||
) as ContextValueType; | ||
return <Context.Provider value={value}>{children}</Context.Provider>; | ||
}; | ||
|
||
Provider.displayName = rootComponentName + 'Provider'; | ||
Provider.displayName = rootComponentName + "Provider"; | ||
|
||
function useContext(consumerName: string) { | ||
const context = React.useContext(Context); | ||
if (context) return context; | ||
if (defaultContext !== undefined) return defaultContext; | ||
// if a defaultContext wasn't specified, it's a required context. | ||
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``); | ||
throw new Error( | ||
`\`${consumerName}\` must be used within \`${rootComponentName}\`` | ||
); | ||
} | ||
|
||
return [Provider, useContext] as const; | ||
} | ||
} |
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