-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add StringParamsProvider for injecting param values to strings (#…
…339)
- Loading branch information
Showing
5 changed files
with
56 additions
and
6 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,5 @@ | ||
--- | ||
'@blinkk/root': patch | ||
--- | ||
|
||
feat: add StringParamsProvider for injecting values to strings |
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,2 +1,2 @@ | ||
// This file is autogenerated by update-root-version.mjs. | ||
export const ROOT_VERSION = '1.0.3'; | ||
export const ROOT_VERSION = '1.0.9'; |
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,39 @@ | ||
import {createContext} from 'preact'; | ||
import {useContext} from 'preact/hooks'; | ||
|
||
export type StringParamsContext = Record<string, string>; | ||
|
||
export const STRING_PARAMS_CONTEXT = createContext<StringParamsContext | null>( | ||
null | ||
); | ||
|
||
export const StringParamsProvider = STRING_PARAMS_CONTEXT.Provider; | ||
|
||
/** | ||
* A hook that returns a map of string params, configured via the | ||
* `StringParamsProvider` context provider. These params are automatically | ||
* applied to the `useTranslations()` hook. | ||
* | ||
* | ||
* Usage: | ||
* | ||
* ``` | ||
* export default function Page() { | ||
* return ( | ||
* <StringParamsProvider value={{name: 'Alice'}}> | ||
* <SayHello /> | ||
* </StringParamsProvider> | ||
* ); | ||
* } | ||
* | ||
* function SayHello() { | ||
* const t = useTranslations(); | ||
* return <h1>{t('Hello, {name}!')}</h1>; | ||
* } | ||
* ``` | ||
* | ||
* This should render `<h1>Hello, Alice!</h1>`. | ||
*/ | ||
export function useStringParams() { | ||
return useContext(STRING_PARAMS_CONTEXT) || {}; | ||
} |
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