-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from Telegram-Mini-Apps/158-add-hook-in-sdk-r…
…eact-to-get-init-data-raw-representation 158 add hook in sdk react to get init data raw representation
- Loading branch information
Showing
7 changed files
with
49 additions
and
32 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 @@ | ||
--- | ||
"@tma.js/sdk-react": minor | ||
--- | ||
|
||
Add `useInitDataRaw` utility to retrieve init data raw representation. |
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,43 @@ | ||
import React, { type ComponentType } from 'react'; | ||
import type { InitData } from '@tma.js/sdk'; | ||
|
||
import { useUnit } from '../provider/index.js'; | ||
|
||
interface EnhancedProps { | ||
initData: InitData | null; | ||
initDataRaw: string | null; | ||
} | ||
|
||
/** | ||
* Returns InitData component instance. | ||
*/ | ||
export function useInitData(): InitData | null { | ||
return useUnit('initData') || null; | ||
} | ||
|
||
/** | ||
* Returns init data raw representation. | ||
*/ | ||
export function useInitDataRaw(): string | null { | ||
return useUnit('initDataRaw') || null; | ||
} | ||
|
||
/** | ||
* HOC which passes InitData SDK component to wrapped React component. | ||
* @param Component - component to wrap. | ||
*/ | ||
export function withInitData<P extends Partial<EnhancedProps>>( | ||
Component: ComponentType<P>, | ||
): ComponentType<Omit<P, keyof EnhancedProps>> { | ||
return function WithInitData(props) { | ||
const enhancedProps = { | ||
...props, | ||
initData: useInitData(), | ||
initDataRaw: useInitDataRaw(), | ||
} as P; | ||
|
||
return <Component {...enhancedProps} />; | ||
}; | ||
} | ||
|
||
export { InitData }; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
336cd5e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./apps/docs
docs-git-master-telegram-mini-apps.vercel.app
tma-js-docs.vercel.app
docs-telegram-mini-apps.vercel.app
docs.telegram-mini-apps.com