{"record":{"id":"edc5d4ee419ceed8","repo":"facebook/react","slug":"componentwillmount-has-been-renamed-and-is-not-re","errorCode":null,"errorMessage":"componentWillMount has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.\n\n* Move code with side effects to componentDidMount, and set initial state in the constructor.\n* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\nPlease update the following components: %s","messagePattern":"componentWillMount has been renamed, and is not recommended for use\\. See https://react\\.dev/link/unsafe-component-lifecycles for details\\.\n\n\\* Move code with side effects to componentDidMount, and set initial state in the constructor\\.\n\\* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode\\. In React 18\\.x, only the UNSAFE_ name will work\\. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder\\.\n\nPlease update the following components: %s","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/react-reconciler/src/ReactStrictModeWarnings.js","lineNumber":234,"sourceCode":"\n    if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {\n      const sortedNames = setToSortedString(\n        UNSAFE_componentWillUpdateUniqueNames,\n      );\n      console.error(\n        'Using UNSAFE_componentWillUpdate in strict mode is not recommended ' +\n          'and may indicate bugs in your code. ' +\n          'See https://react.dev/link/unsafe-component-lifecycles for details.\\n\\n' +\n          '* Move data fetching code or side effects to componentDidUpdate.\\n' +\n          '\\nPlease update the following components: %s',\n        sortedNames,\n      );\n    }\n\n    if (componentWillMountUniqueNames.size > 0) {\n      const sortedNames = setToSortedString(componentWillMountUniqueNames);\n\n      console.warn(\n        'componentWillMount has been renamed, and is not recommended for use. ' +\n          'See https://react.dev/link/unsafe-component-lifecycles for details.\\n\\n' +\n          '* Move code with side effects to componentDidMount, and set initial state in the constructor.\\n' +\n          '* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' +\n          'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +\n          'To rename all deprecated lifecycles to their new names, you can run ' +\n          '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\\n' +\n          '\\nPlease update the following components: %s',\n        sortedNames,\n      );\n    }\n\n    if (componentWillReceivePropsUniqueNames.size > 0) {\n      const sortedNames = setToSortedString(\n        componentWillReceivePropsUniqueNames,\n      );\n\n      console.warn(","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactStrictModeWarnings.js#L216-L252","documentation":"ReactStrictModeWarnings records every class component mounted under StrictLegacyMode that defines componentWillMount without the UNSAFE_ prefix (unless the method carries __suppressDeprecationWarning, as set by react-lifecycles-compat). The batch is flushed as this console.warn listing the sorted component names. componentWillMount is unsafe under concurrent rendering because React may invoke it multiple times before commit, so React 18+ requires moving it or renaming it.","triggerScenarios":"In a dev build, rendering <StrictMode><LegacyClass /></StrictMode> where LegacyClass.prototype.componentWillMount is a function. Detection happens during the strict-mode remount pass; each component type is listed once.","commonSituations":"Adding <StrictMode> when upgrading to React 18/19 over a pre-16.3 codebase; older class-based UI libraries shipping componentWillMount; tutorial code ported forward.","solutions":["Move side effects to componentDidMount and set initial state in the constructor","Run `npx react-codemod rename-unsafe-lifecycles` to bulk-rename remaining cases to UNSAFE_componentWillMount","For third-party components, upgrade the library or shim with react-lifecycles-compat (its __suppressDeprecationWarning flag silences detection)","Rename manually with UNSAFE_ only as a stopgap - in React 18.x only the UNSAFE_ name works"],"exampleFix":"// before\nclass Example extends React.Component {\n  componentWillMount() { this.fetch(this.props.id); }\n}\n\n// after\nclass Example extends React.Component {\n  state = { data: null };\n  componentDidMount() { this.fetch(this.props.id); }\n}","handlingStrategy":"type-guard","validationCode":"// dev-time audit before mounting third-party classes\nconst LEGACY = ['componentWillMount'];\nfunction usesLegacyLifecycle(ctor) {\n  const proto = ctor && ctor.prototype;\n  if (!proto) return false;\n  return LEGACY.some(\n    name =>\n      typeof proto[name] === 'function' &&\n      proto[name].__suppressDeprecationWarning !== true,\n  );\n}\nif (__DEV__ && usesLegacyLifecycle(LibraryWidget)) {\n  console.warn('LibraryWidget ships componentWillMount - upgrade it');\n}","typeGuard":"function definesComponentWillMount(ctor) {\n  const m = ctor && ctor.prototype && ctor.prototype.componentWillMount;\n  return typeof m === 'function' && m.__suppressDeprecationWarning !== true;\n}","tryCatchPattern":null,"preventionTips":["Run `npx react-codemod rename-unsafe-lifecycles` during React 18/19 upgrades","Keep <StrictMode> enabled in development to surface these early","Write new UI as function components so legacy lifecycles cannot reappear","Check dependencies for __suppressDeprecationWarning-polyfilled compat before overriding"],"tags":["legacy-lifecycles","component-will-mount","class-components","strict-mode","deprecation"],"backgroundTag":"unsafe-component-lifecycles","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}