inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

인프런 워밍업 클럽 스터디 1기 FE 과제(10번 과제)

이슬
0

[10번 과제(Day11) - 포켓몬 도감 앱]

따라하며 배우는 리액트 A-Z

학습 범위: Section 6 ~ 7

https://github.com/helloleesul/inflearn-warmup-club-study/tree/main/pokedex-app

과제 이미지

image

알게된 것 (String, Array 타입에서의 includes 메서드)

// Main Page
// 포켓몬 이름(string)에 검색input이 포함된 것만 필터해서 반환
    const matched = pokemonList.filter(
      (pokemon) => pokemon.name.includes(searchInput) // true인 객체들만 반환
    );
    // 검색input값이 있을 때에만 검색 결과 배열에 저장
    if (searchInput) {
      setSearchResults(matched);
    }

// String.prototype.includes
const sentence = 'The quick brown fox jumps over the lazy dog.';
console.log(sentence.includes('quick')); // true
console.log(sentence.includes('h')); // true
console.log(sentence.includes('Quick')); // false, 대소문자 구분
// SearchBar
// 검색input 값이 검색 이름(array)에 포함된 경우 true일 때 (정확히 같아야 함)
    if (searchResults.map((result) => result.name).includes(searchInput)) {
      setSearchShow(false); // 연관 검색 숨기기
    }

// Array.prototype.includes
const fruits = ['apple', 'banana', 'mango'];
console.log(fruits.includes('banana')); // true
console.log(fruits.includes('ba')); // false

 

웹 개발 인프런 워밍업클럽 FE 1기 과제

답변 0