What you were expecting:
If I use ReferenceInput with AutocompleteInput and set filter prop (aka permanentFilter) to a variable, data filter should update alongside the variable.
Example: I have user select input for author_id, in the following ReferenceInput->AutoComplete Input for books I want to filter for whatever author_id was selected (pulling value either from formState.values or FormDataConsumer's formData) and filterToQuery on book's title:
filter={ formData && formData.author_id ? {author_id: formData.author_id} : {} }filterToQuery={(searchText: string) => ({ title: searchText })}
What happened instead:
useFilterState is always setting permanentFilter to whatever it originally loaded in with. In the above case, it will always be undefined because formData.author_id doesn't update until user selects author. Once they select author_id=23 it will still be read from the original undefined value.
Steps to reproduce:
Set a RefeneceInput's filter prop to another input on form (see above example or CodePen below)
It's hard to demonstrate fully with data set there but if you open console you'll see on tag_id select an initial call is made with "filter":{"tag_id":16,"body":""}} but every following call looks like "filter":{"body":"test"}} because tag_id (taken from dataForm.tag_id) is read as undefined in useFilterState.
Other information:
In useFilterState, replacing permanentFilter with permanentFilterProp.current (e.g. latest filter prop value) in setFilterValue seems to fix but unsure if that could cause issues elsewhere.
This may very well relate to issue #3921
This is my first issue here so please let me know if I can clear anything up. React-Admin is an invaluable part of my team's app and we very much value all the hard work you do here!
Environment
React-admin version: 3.2.3
Last version that did not exhibit the issue (if applicable): It seems this came with the major hooks 3.0 update. This worked before.
What you were expecting: If I use ReferenceInput with AutocompleteInput and set filter prop (aka permanentFilter) to a variable, data filter should update alongside the variable.
Example: I have user select input for author_id, in the following ReferenceInput->AutoComplete Input for books I want to filter for whatever author_id was selected (pulling value either from formState.values or FormDataConsumer's formData) and filterToQuery on book's title:
filter={ formData && formData.author_id ? {author_id: formData.author_id} : {} }
filterToQuery={(searchText: string) => ({ title: searchText })}
What happened instead: useFilterState is always setting permanentFilter to whatever it originally loaded in with. In the above case, it will always be undefined because formData.author_id doesn't update until user selects author. Once they select author_id=23 it will still be read from the original undefined value.
Steps to reproduce: Set a RefeneceInput's filter prop to another input on form (see above example or CodePen below)
Related code: Please go to posts -> PostCreate.js for code example: https://codesandbox.io/s/focused-snyder-ereg7
It's hard to demonstrate fully with data set there but if you open console you'll see on tag_id select an initial call is made with
"filter":{"tag_id":16,"body":""}}
but every following call looks like"filter":{"body":"test"}}
because tag_id (taken from dataForm.tag_id) is read asundefined
in useFilterState.Other information: In useFilterState, replacing
permanentFilter
withpermanentFilterProp.current
(e.g. latest filter prop value) in setFilterValue seems to fix but unsure if that could cause issues elsewhere.This may very well relate to issue #3921
This is my first issue here so please let me know if I can clear anything up. React-Admin is an invaluable part of my team's app and we very much value all the hard work you do here!
Environment