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>} fallback={<Text>Loading</Text>}
documentTitle={{ documentTitle={{
format: (options, route) => formatter: (options, route) =>
`${options?.title ?? route?.name} - React Navigation Example`, `${options?.title ?? route?.name} - React Navigation Example`,
}} }}
> >

View File

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

View File

@@ -9,7 +9,7 @@ export default function useDocumentTitle(
ref: React.RefObject<NavigationContainerRef>, ref: React.RefObject<NavigationContainerRef>,
{ {
enabled = true, enabled = true,
format = (options, route) => options?.title ?? route?.name, formatter = (options, route) => options?.title ?? route?.name,
}: DocumentTitleOptions = {} }: DocumentTitleOptions = {}
) { ) {
React.useEffect(() => { React.useEffect(() => {
@@ -20,7 +20,7 @@ export default function useDocumentTitle(
const navigation = ref.current; const navigation = ref.current;
if (navigation) { if (navigation) {
const title = format( const title = formatter(
navigation.getCurrentOptions(), navigation.getCurrentOptions(),
navigation.getCurrentRoute() navigation.getCurrentRoute()
); );
@@ -29,7 +29,7 @@ export default function useDocumentTitle(
} }
return navigation?.addListener('options', (e) => { return navigation?.addListener('options', (e) => {
const title = format(e.data.options, navigation?.getCurrentRoute()); const title = formatter(e.data.options, navigation?.getCurrentRoute());
document.title = title; document.title = title;
}); });