refactor: change format to formatter for documentTitle option

This commit is contained in:
Satyajit Sahoo
2020-07-10 13:07:47 +02:00
parent 13c9d1e281
commit eea9860323
3 changed files with 5 additions and 5 deletions

View File

@@ -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`,
}}
>

View File

@@ -55,7 +55,7 @@ export type LinkingOptions = {
export type DocumentTitleOptions = {
enabled?: boolean;
format?: (
formatter?: (
options: Record<string, any> | undefined,
route: Route<string> | undefined
) => string;

View File

@@ -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;
});