--- id: strict-mode title: Strict Mode permalink: docs/strict-mode.html --- `StrictMode` is a tool for highlighting potential problems in an application. Like `Fragment`, `StrictMode` does not render any visible UI. It activates additional checks and warnings for its descendants. > Note: > > Strict mode checks are run in development mode only; _they do not impact the production build_. You can enable strict mode for any part of your application. For example: `embed:strict-mode/enabling-strict-mode.js` In the above example, strict mode checks will *not* be run against the `Header` and `Footer` components. However, `ComponentOne` and `ComponentTwo`, as well as all of their descendants, will have the checks. `StrictMode` currently helps with: * [Identifying components with unsafe lifecycles](#identifying-unsafe-lifecycles) * [Warning about legacy string ref API usage](#warning-about-legacy-string-ref-api-usage) * [Warning about deprecated findDOMNode usage](#warning-about-deprecated-finddomnode-usage) * [Detecting unexpected side effects](#detecting-unexpected-side-effects) * [Detecting legacy context API](#detecting-legacy-context-api) Additional functionality will be added with future releases of React. ### Identifying unsafe lifecycles {#identifying-unsafe-lifecycles} As explained [in this blog post](/blog/2018/03/27/update-on-async-rendering.html), certain legacy lifecycle methods are unsafe for use in async React applications. However, if your application uses third party libraries, it can be difficult to ensure that these lifecycles aren't being used. Fortunately, strict mode can help with this! When strict mode is enabled, React compiles a list of all class components using the unsafe lifecycles, and logs a warning message with information about these components, like so: ![](../images/blog/strict-mode-unsafe-lifecycles-warning.png) Addressing the issues identified by strict mode _now_ will make it easier for you to take advantage of concurrent rendering in future releases of React. ### Warning about legacy string ref API usage {#warning-about-legacy-string-ref-api-usage} Previously, React provided two ways for managing refs: the legacy string ref API and the callback API. Although the string ref API was the more convenient of the two, it had [several downsides](https://github.com/facebook/react/issues/1373) and so our official recommendation was to [use the callback form instead](/docs/refs-and-the-dom.html#legacy-api-string-refs). React 16.3 added a third option that offers the convenience of a string ref without any of the downsides: `embed:16-3-release-blog-post/create-ref-example.js` Since object refs were largely added as a replacement for string refs, strict mode now warns about usage of string refs. > **Note:** > > Callback refs will continue to be supported in addition to the new `createRef` API. > > You don't need to replace callback refs in your components. They are slightly more flexible, so they will remain as an advanced feature. [Learn more about the new `createRef` API here.](/docs/refs-and-the-dom.html) ### Warning about deprecated findDOMNode usage {#warning-about-deprecated-finddomnode-usage} React used to support `findDOMNode` to search the tree for a DOM node given a class instance. Normally you don't need this because you can [attach a ref directly to a DOM node](/docs/refs-and-the-dom.html#creating-refs). `findDOMNode` can also be used on class components but this was breaking abstraction levels by allowing a parent to demand that certain children was rendered. It creates a refactoring hazard where you can't change the implementation details of a component because a parent might be reaching into its DOM node. `findDOMNode` only returns the first child, but with the use of Fragments, it is possible for a component to render multiple DOM nodes. `findDOMNode` is a one time read API. It only gave you an answer when you asked for it. If a child component renders a different node, there is no way to handle this change. Therefore `findDOMNode` only worked if components always return a single DOM node that never changes. You can instead make this explicit by passing a ref to your custom component and pass that along to the DOM using [ref forwarding](/docs/forwarding-refs.html#forwarding-refs-to-dom-components). You can also add a wrapper DOM node in your component and attach a ref directly to it. ```javascript{4,7} class MyComponent extends React.Component { constructor(props) { super(props); this.wrapper = React.createRef(); } render() { return