Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalise how we write stories #294

Merged
merged 1 commit into from
Dec 10, 2024
Merged

Normalise how we write stories #294

merged 1 commit into from
Dec 10, 2024

Conversation

sandhose
Copy link
Member

@sandhose sandhose commented Dec 10, 2024

When upgrading to React 19, I had a few typing errors, mainly because we're not consistent when writing stories.

This changes to always use the following pattern:

const meta = {
  // ...
  component: Component,
} satisfies Meta<typeof Component>;
export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
  // ...
};

This has the main benefit of making sure that the story is typed correctly:

  • the story object themselves are typed as expected
  • the 'as Meta' cast we used hide a few typing errors, satisfies makes sure the Meta is correctly typed
  • defining Story as StoryObj<typeof meta> makes sure that if we have mandatory args defined in the meta, we don't have to define them in the story

It also tries to use decorators and the children arg as much as possible instead of defining story-specific render functions

Copy link

cloudflare-workers-and-pages bot commented Dec 10, 2024

Deploying compound-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5e3b9c9
Status: ✅  Deploy successful!
Preview URL: https://73bf1a38.compound-web.pages.dev
Branch Preview URL: https://quenting-normalise-stories.compound-web.pages.dev

View logs

@sandhose sandhose requested a review from a team as a code owner December 10, 2024 10:46
@sandhose sandhose requested review from dbkr and robintown and removed request for a team December 10, 2024 10:46
@sandhose sandhose force-pushed the quenting/normalise-stories branch from f790bc2 to 4fb55a7 Compare December 10, 2024 10:52
@sandhose sandhose force-pushed the quenting/normalise-stories branch from 4fb55a7 to 5e3b9c9 Compare December 10, 2024 10:56
@sandhose sandhose merged commit 945a3f5 into main Dec 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants