mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-12 22:51:18 +08:00
refactor: change format to formatter for documentTitle option
This commit is contained in:
@@ -278,7 +278,7 @@ export default function App() {
|
||||
}}
|
||||
fallback={<Text>Loading…</Text>}
|
||||
documentTitle={{
|
||||
format: (options, route) =>
|
||||
formatter: (options, route) =>
|
||||
`${options?.title ?? route?.name} - React Navigation Example`,
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -55,7 +55,7 @@ export type LinkingOptions = {
|
||||
|
||||
export type DocumentTitleOptions = {
|
||||
enabled?: boolean;
|
||||
format?: (
|
||||
formatter?: (
|
||||
options: Record<string, any> | undefined,
|
||||
route: Route<string> | undefined
|
||||
) => string;
|
||||
|
||||
@@ -9,7 +9,7 @@ export default function useDocumentTitle(
|
||||
ref: React.RefObject<NavigationContainerRef>,
|
||||
{
|
||||
enabled = true,
|
||||
format = (options, route) => options?.title ?? route?.name,
|
||||
formatter = (options, route) => options?.title ?? route?.name,
|
||||
}: DocumentTitleOptions = {}
|
||||
) {
|
||||
React.useEffect(() => {
|
||||
@@ -20,7 +20,7 @@ export default function useDocumentTitle(
|
||||
const navigation = ref.current;
|
||||
|
||||
if (navigation) {
|
||||
const title = format(
|
||||
const title = formatter(
|
||||
navigation.getCurrentOptions(),
|
||||
navigation.getCurrentRoute()
|
||||
);
|
||||
@@ -29,7 +29,7 @@ export default function useDocumentTitle(
|
||||
}
|
||||
|
||||
return navigation?.addListener('options', (e) => {
|
||||
const title = format(e.data.options, navigation?.getCurrentRoute());
|
||||
const title = formatter(e.data.options, navigation?.getCurrentRoute());
|
||||
|
||||
document.title = title;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user