Skip to content

Commit

Permalink
refactor: use Object.entries instead of reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jan 11, 2024
1 parent 9986736 commit 13b79eb
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,22 @@ const linking: LinkingOptions<RootStackParamList> = {
},
},
NotFound: '*',
...SCREEN_NAMES.reduce(
(acc, name) => {
...Object.fromEntries(
Object.entries(SCREENS).map(([name, { linking }]) => {
// Convert screen names such as SimpleStack to kebab case (simple-stack)
const path = name
.replace(/([A-Z]+)/g, '-$1')
.replace(/^-/, '')
.toLowerCase();

const config = {
path,
screens: SCREENS[name].linking,
};

// @ts-expect-error: acc is not readonly
acc[name] = config;

return acc;
},
{} as {
[Key in keyof typeof SCREENS]: {
path: string;
screens: (typeof SCREENS)[Key]['linking'];
};
}
return [
name,
{
path,
screens: linking,
},
];
})
),
},
},
Expand Down

0 comments on commit 13b79eb

Please sign in to comment.