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

Create button doesn't re-render on disabled prop change #5865

Closed
andrico1234 opened this issue Feb 4, 2021 · 0 comments
Closed

Create button doesn't re-render on disabled prop change #5865

andrico1234 opened this issue Feb 4, 2021 · 0 comments

Comments

@andrico1234
Copy link
Contributor

andrico1234 commented Feb 4, 2021

I have a component:

export function Actions(props) {
  const [isDisabled, setDisabledState] = useState(true);

  return (
    <TopToolbar {...sanitizeListRestProps(props)}>
      <Button
        onClick={() => {
          setDisabledState(!isDisabled);
        }}
        label="Toggle state"
      >
        <ClearAllIcon />
      </Button>
      <CreateButton disabled={isDisabled} label="Create Patient" />
    </TopToolbar>
  );
}

I expect the disabled state to toggle when after clicking the Toggle state button. Instead nothing happens, the CreateButton doesn't rerender.

This looks like a similar issue faced in this ticket. I imagine the solution would be to add an additional check to see if the disabled prop has changed.

I'm not too sure if this is a specific design choice to avoid this rerendering when this particular prop changes, but I can't see why it's not supported given this example in the docs shows the disabled attribute being used.

I've recreated this in the codesandbox: https://codesandbox.io/s/romantic-keldysh-bh10v?file=/src/posts/PostList.js

If you guys are fine with this, I can quickly get a PR going. I imagine it's a simple one line change

Edit: I ended up making an MR for this

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

No branches or pull requests

1 participant