Skip to content

Commit

Permalink
Fixes #254. Use flatMap() instead of reduce() to flatten an array.
Browse files Browse the repository at this point in the history
  • Loading branch information
molefrog committed Feb 26, 2024
1 parent c5efa2e commit 67abe0e
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions packages/wouter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,12 @@ export const Link = forwardRef((props, ref) => {
: h("a", { ...restProps, href, onClick, children, ref });
});

const flattenChildren = (children) => {
return Array.isArray(children)
? [].concat(
...children.map((c) =>
c && c.type === Fragment
? flattenChildren(c.props.children)
: flattenChildren(c)
)
const flattenChildren = (children) =>
Array.isArray(children)
? children.flatMap((c) =>
flattenChildren(c && c.type === Fragment ? c.props.children : c)
)
: [children];
};

export const Switch = ({ children, location }) => {
const router = useRouter();
Expand Down

0 comments on commit 67abe0e

Please sign in to comment.