Skip to content

Commit

Permalink
Merge pull request #266 from sparksuite/demo-site-crash-fix
Browse files Browse the repository at this point in the history
Refactor pattern of spreading empty arrays to Array.from
  • Loading branch information
WesCossick authored Apr 23, 2021
2 parents 3d7aa9f + 15bb24f commit 09208ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-accessible-dropdown-menu-hook",
"version": "2.2.0",
"version": "2.2.1",
"description": "A simple Hook for creating fully accessible dropdown menus in React",
"main": "dist/use-dropdown-menu.js",
"types": "dist/use-dropdown-menu.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/use-dropdown-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function useDropdownMenu(itemCount: number): DropdownMenuResponse

// Initialize refs and update them when the item count changes
useEffect(() => {
itemRefs.current = [...Array<undefined>(itemCount)].map(() => createRef<HTMLAnchorElement>());
itemRefs.current = Array.from({ length: itemCount }, () => createRef<HTMLAnchorElement>());
}, [itemCount]);

// Create type guard
Expand Down Expand Up @@ -199,7 +199,7 @@ export default function useDropdownMenu(itemCount: number): DropdownMenuResponse
'aria-expanded': isOpen,
};

const itemProps = [...Array<undefined>(itemCount)].map((_ignore, index) => ({
const itemProps = Array.from({ length: itemCount }, (_ignore, index) => ({
onKeyDown: itemListener,
tabIndex: -1,
role: 'menuitem',
Expand Down

0 comments on commit 09208ac

Please sign in to comment.