Skip to content

Commit

Permalink
Add migration notes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Nov 14, 2022
1 parent 4d637a5 commit ceca15e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 39 additions & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
- [7.0 Deprecations](#70-deprecations)
- [`Story` type deprecated](#story-type-deprecated)
- [`ComponentStory`, `ComponentStoryObj`, `ComponentStoryFn` and `ComponentMeta` types are deprecated](#componentstory-componentstoryobj-componentstoryfn-and-componentmeta-types-are-deprecated)
- [Renamed `renderToDOM` to `renderToCanvas`](#renamed-rendertodom-to-rendertoroot)
- [Renamed `renderToDOM` to `renderToCanvas`](#renamed-rendertodom-to-rendertocanvas)
- [Renamed `XFramework` to `XRenderer`](#renamed-xframework-to-xrenderer)
- [Renamed `DecoratorFn` to `Decorator`](#renamed-decoratorfn-to-decorator)
- [From version 6.4.x to 6.5.0](#from-version-64x-to-650)
- [Vue 3 upgrade](#vue-3-upgrade)
- [React18 new root API](#react18-new-root-api)
Expand Down Expand Up @@ -864,6 +865,43 @@ import type { SvelteRenderer } from '@storybook/svelte';
// etc.
```

#### Renamed `DecoratorFn` to `Decorator`

In 6.x you could import the type `DecoratorFn`:

```ts
import type { DecoratorFn } from '@storybook/react';
// etc.
```

This type is deprecated in 7.0, instead you can use the type `Decorator`:

```ts
import type { Decorator } from '@storybook/react';
// etc.
```

The type `Decorator` accepts a generic parameter `TArgs`. This can be used like this:

```tsx
import type { Decorator } from '@storybook/react';

const withTheme: Decorator<{ theme: 'light' | 'dark' }> = (Story, { args }) => (
<ThemeProvider theme={args.theme}>
<Story />
</ThemeProvider>
);
```

If you want to use `Decorator` in a backwards compatible way to `DecoratorFn`, you can use:

```tsx
import type { Args, Decorator } from '@storybook/react';

// same Decorator<Args> is the same as the old DecartorFn
const withTheme: Decorator<Args> = (Story, {args}) => // args has type { [name: string]: any }
```
## From version 6.4.x to 6.5.0
### Vue 3 upgrade
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/react/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export type ComponentStory<T extends JSXElement> = ComponentStoryFn<T>;
/**
* @deprecated Use Decorator instead.
*/
export type DecoratorFn<TArgs = Args> = DecoratorFunction<ReactRenderer, TArgs>;
export type DecoratorFn = DecoratorFunction<ReactRenderer>;
export type Decorator<TArgs = StrictArgs> = DecoratorFunction<ReactRenderer, TArgs>;
export type Loader<TArgs = StrictArgs> = LoaderFunction<ReactRenderer, TArgs>;
export type StoryContext<TArgs = StrictArgs> = GenericStoryContext<ReactRenderer, TArgs>;

0 comments on commit ceca15e

Please sign in to comment.