Multiple filters in React

后端 未结 2 524
北恋
北恋 2020-12-22 04:41

I am building a project that displays some data from api and now I need to filter it.

I\'ve done the category filter and now I have to do a price range filter so bot

2条回答
  •  忘掉有多难
    2020-12-22 05:42

    i have same problem with marge filters i have two filters and each one works fine but together not works only first work my code is

    const [search, setSearch] = useState('');
    const [select, setSelect] = useState('All');
    
    
    const updateSearch = (e) => {
        setSearch(e.target.value);
        //console.log(search);
      }
    
    const updateSelect = (e) => {
        setSelect(e.target.value);
        //console.log(select);
    }
    
    const searchCountry = zemlje.filter((zemlja) => {
        if (zemlja.name.toLowerCase().search(new RegExp(`^${search}`)) === 0) return true;
    });
    
    const selectCountry = zemlje.filter((zemlja) => {
        if (select ==='All') return true;
        if (zemlja.region === select) return true;
    });
    

    i want filter this base on search input and select drop menu

            
    {searchCountry.map(zemlja => ( ))}

提交回复
热议问题