Strict 모드는 애플리케이션 내의 잠재적인 문제를 강조해준다.
Strict 모드는 개발 모드에서만 활성화되기 때문에, 프로덕션 빌드에는 영향을 끼치지 않는다.
React 패키지에 포함되어 있으며, CRA를 통해서 프로젝트 생성 시 default로 감싸져 있다.
애플리케이션 내 어디서든지 아래와 같이 strict 모드를 활성화할 수 있다.
import React, { StrictMode } from 'react';
function ExampleApplication() {
return (
<div>
<Header />
**<StrictMode>**
<div>
<ComponentOne />
<ComponentTwo />
</div>
**</StrictMode>**
<Footer />
</div>
);
}
위의 예시에서, Header
와 Footer
컴포넌트는 Strict 모드 검사가 이루어지지 않고, ComponentOne
과 ComponentTwo
는 각각의 자손까지 검사가 이루어진다.
StrictMode
는 오래된 메소드나 React 관련 기능에 대한 경고를 알려준다.
componentWillMount
componentWillReceiveProps
componentWillUpdate