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

Addon-docs: Inline rendering support for loaders #12726

Open
shilman opened this issue Oct 10, 2020 · 6 comments
Open

Addon-docs: Inline rendering support for loaders #12726

shilman opened this issue Oct 10, 2020 · 6 comments

Comments

@shilman
Copy link
Member

shilman commented Oct 10, 2020

#12699 adds async loaders to CSF, but the loaded data is not yet compatible with Storybook Docs inline rendering. Until this is added, the loaded data is undefined.

@giorgiabosello
Copy link

giorgiabosello commented Nov 15, 2021

You could add inlineStories: false to the docs parameters of your story to bypass this error, and then declare a new source code template to render the code correctly in storybook.
Ex.

const MyStory = {
	title: '',
	component: MyComponent,
	parameters: {
		docs: {
			inlineStories: false,
		}
	}
	loaders: [
		async () => ({
			configs: (await getConfigs()).data,
		}),
	],
}

export default MyStory

export const Default = (args, { loaded: { configs } }) => (
	<MyComponent {...args} {...configs} />
)

// this is what you will see on the Docs page.
const MyStoryCodeTemplate = (MyComponent) => `
<${MyComponent} {...props} />
`

Default.parameters = {
	docs: {
		source: {
			code: MyStoryCodeTemplate('MyComponent'),
		},
	},
}

@MichaelAllenWarner
Copy link

Looks like #14911 (which mentions this issue) was merged, but that it did not actually resolve this issue.

@shilman
Copy link
Member Author

shilman commented Nov 22, 2021

@MichaelAllenWarner no it was closed, not merged

@MichaelAllenWarner
Copy link

Oops—I blame my head cold.

@esharmony
Copy link

Is it still the case that I cannot use loaders in the docs, I am getting undefined as mentioned in this issue, but the issue is quite old.

@itsalb3rt
Copy link

itsalb3rt commented May 9, 2022

You could add inlineStories: false to the docs parameters of your story to bypass this error, and then declare a new source code template to render the code correctly in storybook. Ex.

const MyStory = {
	title: '',
	component: MyComponent,
	parameters: {
		docs: {
			inlineStories: false,
		}
	}
	loaders: [
		async () => ({
			configs: (await getConfigs()).data,
		}),
	],
}

export default MyStory

export const Default = (args, { loaded: { configs } }) => (
	<MyComponent {...args} {...configs} />
)

// this is what you will see on the Docs page.
const MyStoryCodeTemplate = (MyComponent) => `
<${MyComponent} {...props} />
`

Default.parameters = {
	docs: {
		source: {
			code: MyStoryCodeTemplate('MyComponent'),
		},
	},
}

Thanks! This working for me in version 6.4.22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants