✍️ 내가 짠 코드
const [inputValue, setInputValue] = useState("");
const filtering = () => {
return inputValue === ''
? []
: products.filter(product =>
product.name.toLowerCase().includes(inputValue.toLowerCase())
동사 + 명사
로 짓는게 좋다. (변수명만으로도 무슨 기능을 하는지 파악이 가능해야 함!)filtering
-> filterProducts
const filterProducts = (inputValue) => {
if(!inputValue) return [];
return products.filter(product =>
product.name.toLowerCase().includes(inputValue.toLowerCase())
// query는 input value
Re-refactoring
const filteredProducts = products.filter(product =>
product.name.toLowerCase().includes(inputValue.toLowerCase()))