Number control does not update when using useArgs hook
See original GitHub issueDescribe the bug
I’m using useArgs
hook in my component’s template to sync controls value when the state is changed via function handler.
// Brief view of the story ./stories/Counter.stories.tsx
const Template: ComponentStory<typeof Counter> = (args) => {
const [{ primary, count }, updateArgs] = useArgs();
const handleChange = () => updateArgs({ primary: !primary });
const handleClickUp = () => updateArgs({ count: count + 1 });
const handleClickDown = () => updateArgs({ count: count - 1 });
return (
<div>
<Counter {...args} handleChange={handleChange} handleClickDown={handleClickDown} handleClickUp={handleClickUp} />
</div>
);
};
Everything works with boolean type, but when updateArgs
updates a number, the control tab does not update and shows the previous/initial value.
To Reproduce Repo to reproduce: https://github.com/zygisau/use-args-number-type-control-bug-repro
- Go to Example/Counter/Primary story (image below).
- Press +1 a couple of times.
Expected behaviour
- Count value in the control tab is updated with the new value.
Actual behaviour
- Count value did not update (image below).
System
Environment Info:
System:
OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
Binaries:
Node: 14.16.1 - /usr/local/bin/node
Yarn: 3.0.1 - /mnt/c/Users/zygimantas/AppData/Roaming/npm/yarn
npm: 6.14.12 - /usr/local/bin/npm
npmPackages:
@storybook/addon-actions: ^6.4.0-alpha.32 => 6.4.0-alpha.32
@storybook/addon-docs: ^6.4.0-alpha.32 => 6.4.0-alpha.32
@storybook/addon-essentials: ^6.4.0-alpha.32 => 6.4.0-alpha.32
@storybook/addon-links: ^6.4.0-alpha.32 => 6.4.0-alpha.32
@storybook/react: ^6.4.0-alpha.32 => 6.4.0-alpha.32
Additional context
There are a few interesting points to note:
- Changing count values in the control tab updates every part of the story (component, control, url).
- As I mentioned, changing boolean value “Primary” updates control tab.
- One more thing to note, going from the
Canvas
tab toDocs
updates the value.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Number control does not update when using useArgs hook ...
Describe the bug I'm using useArgs hook in my component's template to sync controls value when the state is changed via function handler....
Read more >Changing args values / state in Storybook (without useState ...
A quick glance at how to change your stories args values within Storybook and ReactJs. To be combined with Storybook Controls.
Read more >Change a storybook arg without creating a custom hook ...
I'm trying to change the value of a story arg while using the standard (recommended) args pattern.
Read more >Args - Storybook - JS.ORG
Storybook is a frontend workshop for building UI components and pages in isolation ... You do not need to modify your underlying component...
Read more >Execution hook examples - NetApp
The following example demonstrates how you can use args in a hook. #!/bin/sh # success_sample_args.sh # # A simple success hook script with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I see that there’s not been much activity for a while on this issue so I was trying to see if I could fix this. I have made a pull request with what I think is a fix for the issue. I’m still pretty new to open source contributions so if there’s anything I missed or need to do differently please let me know.
I think the bug is here: https://github.com/storybookjs/storybook/blob/next/lib/components/src/controls/Number.tsx#L31
We only use the value from “on high” to set the initial state. We need a useEffect hook that listens for changes to value and set the internal state based on this being changed.