Story parameters do not update when they are based on story args
See original GitHub issueDescribe the bug If a story has a parameter set based off another arg of the story, changing the arg control does not update the parameters that depend on it.
Before upgrading from version 5.3.x
, we could control parameters (like graphQL query mocks) using knobs like below (simplified example).
import { boolean } from '@storybook/addon-knobs;
import { useQuery } from 'apollo-client';
import { gql } from 'graphql-tag';
const query = gql`query GetUser() users() { name }`;
const UserProfile = () => {
const { data, error, loading } = useQuery(query);
return data ? <div>{data.users.name}</div> : <div>error</div>;
}
export const BasicStory = () => <UserProfile />;
BasicStory.story = {
parameters: {
apolloMocks: () => ({ Query: () => ({ users: boolean('Error', false) ? () => throw new Error() : { name: 'joe' } }) })
}
}
However, what seems like the “args” equivalent after updating to version 6.3
does not work after the knob changes. The initial value is always used when determining the parameter.
const Template = () => <UserProfile />;
const BasicStory = Template.bind({});
BasicStory.args = { error: false } ;
BasicStory.parameters = {
apolloMocks: () => ({ Query: () => ({ users: BasicStory.args.error ? () => throw new Error() : { name: 'joe' } }) })
}
// BasicStory.args.error is always false
Is the above not the correct way to control parameters using the new args approach?
To Reproduce The repro command failed w/ this error:
An error occurred while executing: `yarn set version berry && yarn config set enableGlobalCache true && yarn config set nodeLinker node-modules`
System Environment Info:
System: OS: macOS 10.15.7 CPU: (12) x64 Intel® Core™ i7-8750H CPU @ 2.20GHz Binaries: Node: 10.24.1 - /usr/local/opt/node@10/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.12 - /usr/local/opt/node@10/bin/npm Browsers: Chrome: 91.0.4472.106 Firefox: 88.0.1 Safari: 14.1 npmPackages: @storybook/addon-actions: ^6.3.0-rc.11 => 6.3.0-rc.11 @storybook/addon-docs: ^6.3.0-rc.11 => 6.3.0-rc.11 @storybook/addon-essentials: ^6.2.9 => 6.2.9 @storybook/addon-knobs: ^6.3.0-next.2 => 6.3.0-next.2 @storybook/addon-links: ^6.3.0-rc.11 => 6.3.0-rc.11 @storybook/addon-viewport: ^6.3.0-rc.11 => 6.3.0-rc.11 @storybook/addons: ^6.3.0-rc.11 => 6.3.0-rc.11 @storybook/preset-create-react-app: ^3.1.7 => 3.1.7 @storybook/react: ^6.3.0-rc.11 => 6.3.0-rc.11
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
@tmeasday That worked perfectly. Thanks again. I’ll close the issue.
@tmeasday Yea, that approach does make sense. I’ll give it a shot. Thanks for the explanation.