DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on • Edited on

3 3

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.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay