연관 내용
[검색 프로세스]
[자동으로 검색하기]
const FETCH_BOARDS = gql`
query fetchBoards($search: String, $page: Int) {
fetchBoards(search: $search, page: $page) {
_id
writer
title
contents
}
}
`;
const [search, setSearch] = useState("");
const onChangeSearch = (event: ChangeEvent<HTMLInputElement>) => {
setSearch(event.target.value);
};
const { data, refetch } = useQuery<
Pick<IQuery, "fetchBoards">,
IQueryFetchBoardsArgs
>(FETCH_BOARDS);
const onClickSearch = () => {
refetch({ search, page: 1 });
};
<button onClick={onClickSearch}>검색하기</button>