반응형
VS Code에는 신규로 컴포넌트를 정의할 때마다 일일이 코드를 작성해야 하는 번거로움을 줄여주는 고마운 플러그인이 있다.
좌측 추가 플러그인 설치탭을 클릭한 뒤 reactjs 라고 입력 후 검색하면 가장 먼저 뜨는 [ Rectjs code snippets ] 이다.
세부정보를 내려서 확인하면 아래와 같이 사용 가능한 단축 트리거들이 나열되어 있다.
Trigger | Content |
rcc→ | class component skeleton |
rrc→ | class component skeleton with react-redux connect |
rrdc→ | class component skeleton with react-redux connect and dispatch |
rccp→< | class component skeleton with prop types after the class |
rcjc→ | class component skeleton without import and default export lines |
rcfc→ | class component skeleton that contains all the lifecycle methods |
rwwd→ | class component without import statements |
rpc→ | class pure component skeleton with prop types after the class |
rsc→ | stateless component skeleton |
rscp→ | stateless component with prop types skeleton |
rscm→ | memoize stateless component skeleton |
rscpm→ | memoize stateless component with prop types skeleton |
rsf→ | stateless named function skeleton |
rsfp→ | stateless named function with prop types skeleton |
rsi→ | stateless component with prop types and implicit return |
fcc→ | class component with flow types skeleton |
fsf→ | stateless named function skeleton with flow types skeleton |
fsc→ | stateless component with flow types skeleton |
rpt→ | empty propTypes declaration |
rdp→ | empty defaultProps declaration |
con→ | class default constructor with props |
conc→ | class default constructor with props and context |
est→ | empty state object |
cwm→ | componentWillMount method |
cdm→ | componentDidMount method |
cwr→ | componentWillReceiveProps method |
scu→ | shouldComponentUpdate method |
cwup→ | componentWillUpdate method |
cdup→ | componentDidUpdate method |
cwun→ | componentWillUnmount method |
gsbu→ | getSnapshotBeforeUpdate method |
gdsfp→ | static getDerivedStateFromProps method |
cdc→ | componentDidCatch method |
ren→ | render method |
sst→ | this.setState with object as parameter |
ssf→ | this.setState with function as parameter |
props→ | this.props |
state→ | this.state |
bnd→ | binds the this of method inside the constructor |
disp→ | MapDispatchToProps redux function |
위의 표를 쭉 훑어보면 rcc와 rsc에 대해 개별적으로 마킹처리를 하였는데, 이 2가지 단축 트리거에 대해 설명해보도록 한다.
rcc는 클래스형 컴포넌트를 생성할 때 사용하는 트리거다.
그리고 rsc는 함수형 컴포넌트를 생성할 때 사용한다.
위 Trigger 표를 자세히 살펴보면 Redux나 Props를 사용하는 컴포넌트 자동완성 구문도 정의되어 있으니, 해당 트리거를 활용하면 코딩 시간을 줄일 때 요긴하게 사용할 수 있다.
반응형