【发布时间】:2022-10-07 21:41:26
【问题描述】:
const initialState = [...properties];
const [location, setLocation] = useState('');
const [startDate, setStartDate] = useState(new Date());
const formattedDate = moment(`${startDate}`).format('MM/DD/YYYY');
const [price, setPrice] = useState('');
const [propertyType, setPropertyType] = useState('');
const [filteredProperties, setFilteredProperties] = useState(properties);
const resetState = () => {
setFilteredProperties([...initialState]);
};
我正在尝试构建一个过滤器,如图所示。我想在每次单击搜索时重置状态,然后通过重置状态进行过滤,但是每次单击提交时它都会过滤数组,并且在第二次提交时永远不会重置,因此数组保持不变或变为空,具体取决于第二次过滤搜索.
完整代码在这里:https://github.com/Quelaan1/real_estate_search_filter/blob/develop/src/Components/Filter/Filter.tsx
【问题讨论】:
-
请分享
properties的来源以及更改/更新的位置。 -
属性源自具有对象数组的 JSON。包含 RealEstate 属性详细信息的对象。 filter 函数应该根据页面上使用的过滤器过滤数组。
标签: reactjs react-hooks