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.

Story parameters do not update when they are based on story args

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jamesonhillcommented, Jun 23, 2021

@tmeasday That worked perfectly. Thanks again. I’ll close the issue.

1reaction
jamesonhillcommented, Jun 23, 2021

@tmeasday Yea, that approach does make sense. I’ll give it a shot. Thanks for the explanation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Args - Storybook - JS.ORG
“Args” are Storybook's mechanism for defining those arguments in a single JavaScript object. Args can be used to dynamically change props, slots, styles, ......
Read more >
Docs controls not updating on args changes HMR ... - GitHub
In any args story: open the story in the DocsPage tab edit an arg in the story file observe the story update but...
Read more >
Story parameters do not update when they are ... - Issuehunt
Describe the bug If a story has a parameter set based off another arg of the story, changing the arg control does not...
Read more >
Changing args values / state in Storybook (without useState ...
A quick glance at how to change your stories args values within Storybook ... See that the isOpen is not synced with the...
Read more >
Dynamically updating args in Storybook from a Vue component
References · useArgs throws exception when used with Story function · Story parameters do not update when they are based on story args...
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