Skip to content

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

Closed

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions