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

Fix CreateButton does not update on 'to' prop change #5014

Merged
merged 1 commit into from
Jul 7, 2020

Conversation

rkfg
Copy link
Contributor

@rkfg rkfg commented Jul 7, 2020

I need the CreateButton to reflect the filter values to prefill the new item form. The use case is like this:

  • filter the data by a couple of fields
  • no expected data found
  • press Create
  • expect those two fields filled with the filter values

It worked almost fine except I needed to refresh the page after setting the filter to make the to property be in sync with the filter (. After some research I found out that this button is exported via memo and it's not updated if the to prop is changed. I replaced the TopToolbar in List and the button is declared like this:

    <CreateButton to={{
      pathname: '/records/create',
      search: `?source=${JSON.stringify({ organization_id: filterValues.organization_id, department_id: filterValues.department_id })}`,
    }} />

When I used a regular button it worked just fine. Not all buttons in ra-ui-materialui are wrapped into memo (the other two I found are ShowButton and CloneButton), I'm not sure if this is an important optimization or if it has some deeper meaning but apparently it might cause this subtle bugs.

@fzaninotto fzaninotto merged commit 5cbf266 into marmelab:master Jul 7, 2020
@fzaninotto
Copy link
Member

Thanks!

@fzaninotto fzaninotto added this to the 3.7.1 milestone Jul 7, 2020
@fzaninotto fzaninotto changed the title Update CreateButton on 'to' prop change Fix CreateButton does not update on 'to' prop change Jul 7, 2020
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

Successfully merging this pull request may close these issues.

2 participants