DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on • Edited on

How to sort stories alphabetically in Storybook (6.2)

file:.storybook/preview.js

export const parameters = { options: { storySort: (a, b) => { const aId = getStoryId(a[1]); const bId = getStoryId(b[1]); return aId === bId ? 0 : aId.localeCompare(bId, undefined, { numeric: true }); } }, }; 
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
joriswitteman profile image
Joris W

Mind sharing where to import getStoryId from?

Collapse
 
cbillowes profile image
Clarice Bouwer

Hello Joris, sorry I only saw your message now. I have not been able to find the exact function but from what I can recall is I am using a[1].kind and b[1].kind.