question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow Promise based Decorators & Async Storybook components

See original GitHub issue

Is your feature request related to a problem? Please describe.

I can’t load async data to my Storybook without resorting some hacky solution proposed by some other Storybook issues relating to Promise/Async.

Describe the solution you’d like

export const basicForm = async () => {
  const { data } = await asyncDataCall()

  return <Form data={data} />
}

Will throw Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.

or

type PromiseCallback = () => Promise<any>

const withData: PromiseCallback = () => axios('some-endpoint')

addDecorator(withData)

Will also throw an error

Describe alternatives you’ve considered

Loading using a render prop component https://github.com/storybookjs/storybook/issues/696

Hacky solution using useEffect & useState in this issue. Basically add the promise inside useEffect, and keep a state counter to see if data has been loaded. https://github.com/storybookjs/storybook/pull/1670, but still has issues.

Are you able to assist bring the feature to reality?

not at the moment

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
agrohscommented, Oct 14, 2020
1reaction
mikestopcontinuescommented, Jun 3, 2020

My use case is for adding dynamically selected decorators. So if ctx.parameters.fileName is ./MONOREPO/packages/viewApp/components/Button, I look for the decorator at ./MONOREPO/packages/viewApp/Storybook.js, with a fallback to a default decorator when the filename doesn’t exist.

I don’t see a fully dynamic way to do this. The solution I’m going to pursue is importing all existing decorators, then using a map to select from them. Not as pretty, but better than nothing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loaders (experimental) - Storybook - JS.ORG
Loaders (experimental) are asynchronous functions that load data for a story and its decorators. A story's loaders run before the story renders, ...
Read more >
Decorating Async JavaScript Functions - Innolitics
Promises are a great tool for simplifying asynchronous code; promises allow developers to abstract away function invocation logic into reusable ...
Read more >
Using Storybook and Mock Service Worker for mocked API ...
Combined with Storybook, MSW empowers an unrivaled experience of component development by providing a seamless way to control both internal and ...
Read more >
10 Storybook Best Practices - DEV Community ‍ ‍
It is based on my experience using Storybook over s. ... Story decorators), all stories of a component (called Component Decorators), ...
Read more >
How to use Testing Library to test Storybook - Medium
In your Storybook stories, you already defined the scenarios of your components. You also set up the necessary decorators (theming, routing, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found