목록전체 글 (106)
기술 블로그
Next.js에서의 서버 컴포넌트와 getServersideProps 그리고 not found dns 동적 스크롤 애니메이션 next.js 공식문서 해설 (13)
import axios from 'axios'; import { useQuery } from 'react-query'; const fetchSuperHero = (heroId) => { return axios.get(`http://localhost:4000/superheroes/${heroId}`); }; export function useSuperHeroesData(heroId) { return useQuery(['super-hero', heroId], () => fetchSuperHero(heroId)); } const { refetch } = useQuery( 'super-heroes', fetchSuperHeroes, { enabled: false, }, ); return ( RQ Super H..
yarn add react-query import axios from 'axios'; import React from 'react'; import { useQuery } from 'react-query'; function RQSuperHeroes() { useQuery('super-heroes', () => { return axios.get('http://localhost:4000/superheroes'); }); return RQSuperHeroes; } export default RQSuperHeroes; useQuery(쿼리키, 프로미스를 리턴하는 콜백함수,{옵션}) 와 같이 기본 구조를 가진다. 인자값 중 쿼리키와 프로미스를 리턴하는 콜백함수는 v4에서 옵션 객체의 queryKey와 queryFn..
프로토타입 기반 상속 js에서 모든 객체는 다른 객체를 프로토타입으로 가진다. // 부모 생성자 함수 function Parent(name) { this.name = name; } // 부모 메서드 추가 Parent.prototype.sayHello = function() { console.log(`Hello, I'm ${this.name}`); }; // 자식 생성자 함수 function Child(name, age) { Parent.call(this, name); // 부모 생성자 호출 this.age = age; } // 프로토타입 체인 설정 Child.prototype = Object.create(Parent.prototype); Child.prototype.constructor = Chi..
왜 Custom Hook을 사용해 비지니스 로직을 분리해야 할까? 프로그래밍에서 가장 중요한 것 중 하나가 중복의 제거이다. 반복되는 상태 관련 로직을 분리하여 재사용 하기위해 사용하였다. Hook 이전에는 고차 컴포넌트와 render props를 활용해여 이를 구현하였다 위 두 개념을 활용한 코드가 container presenter 패턴이다. Container 컴포넌트에서는 로직을 작성하고 이를 props로 하위 컴포넌트에 내려준다. 상위 Wrapper가 많아진다면 Wrapper hell이 발생될 우려가 있고 반면 Custom Hook 을 활용한다면 사용하는 각 컴포넌트에 독립적으로 작성할 수 있다. 즉 Custom Hook은 거창한게 아니라 Hook API를 사용하여 재사용 가능한 코드를 작성하면 ..
보호되어 있는 글입니다.