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

Controls: Reset ArgsTable state when switching stories #14493

Merged
merged 2 commits into from Apr 7, 2021

Conversation

ghengeveld
Copy link
Member

@ghengeveld ghengeveld commented Apr 6, 2021

Issue: #14474

What I did

Added the key prop to force React to create a fresh component rather than reuse a previous instance.
Added a missing dependency to useCallback in two places which could lead to the wrong onChange handler getting called.

This also fixes a similar issue with the JSON raw editor using stale data when switching stories.

How to test

  • Is this testable with Jest or Chromatic screenshots? no
  • Does this need a new example in the kitchen sink apps? no
  • Does this need an update to the documentation? no

If your answer is yes to any of these, please make sure to include it in your PR.

@@ -36,6 +37,7 @@ export const ControlsPanel: FC = () => {
{showWarning && <NoControlsWarning />}
<ArgsTable
{...{
key: path, // resets state when switching stories
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would storyId make more sense here?

Copy link
Member Author

@ghengeveld ghengeveld Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I did that at first but it would then have to be:

{
  key: refId ? `${refId}_${storyId}` : storyId
}

path achieves the same thing but without the added complexity of dealing with refId (it's in the path already).

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shilman shilman merged commit f915818 into next Apr 7, 2021
@shilman shilman deleted the reset-argstable-state branch April 7, 2021 07:51
@shilman shilman added this to the 6.2 stabilization milestone Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants