요구사항 랜덤버튼

필수 SearchInput 옆에 버튼을 하나 배치하고, 이 버튼을 클릭할 시 /api/cats/random 을 호출하여 화면에 뿌리는 기능을 추가합니다. 버튼의 이름은 마음대로 정합니다.

//랜덤 버튼
const $randomButton = document.createElement("button");
this.$randomButton = $randomButton;
this.$randomButton.className = 'RandomButton';
this.$randomButton.textContent = '랜덤고양이';
$wrapper.appendChild($randomButton);

Untitled

.SearchInput {
  width: 80%;
  font-size: 40px;
  padding: 10px 15px;
  height: 76px;
}

.RandomButton{
  width:20%;
  font-size: 20px;
  height: 76px;
  padding:10px;
  vertical-align: top;
  cursor: pointer;
}
const TEMPLATE = '<input type="text">';

class SearchInput {
  constructor({ $target, onSearch, **onRandomSearch** }) {

    //검색 input
    //...생략
    
    //랜덤 버튼
    const $randomButton = document.createElement("button");
    this.$randomButton = $randomButton;
    this.$randomButton.className = 'RandomButton';
    this.$randomButton.textContent = '랜덤고양이';
    $wrapper.appendChild($randomButton);

    //랜덤 버튼 클릭
    **$randomButton.addEventListener('click', e => {
      // onSearch('아'); //클릭시 '아' 라는 검색 결과가 나오는지 확인
      onRandomSearch();
    });**

    console.log("SearchInput created.", this);
  }
  render() {}
}
this.searchInput = new SearchInput({
$target,
onSearch: keyword => {
  //로딩 시작 show
  this.Loading.show();
  api.fetchCats(keyword).then(({ data }) => {
    this.setState(data);
    //로딩 끝 hide
    this.Loading.hide();
  });
},
**onRandomSearch : () => {
  console.log('랜덤?')
}**
});
const API_ENDPOINT =
  "<http://localhost:4001>";

const api = {
  fetchCats: keyword => {
    return fetch(`${API_ENDPOINT}/api/cats/search?q=${keyword}`).then(res =>
      res.json()
    );
  },
  **fetchRandomCats : () => {
    return fetch(`${API_ENDPOINT}/api/cats/random`).then(res =>
      res.json()
    );
  }**
};