@@ -64,12 +64,14 @@ let didWarnAboutLegacyLifecyclesAndDerivedState;
6464let didWarnAboutUndefinedDerivedState ;
6565let warnOnUndefinedDerivedState ;
6666let warnOnInvalidCallback ;
67+ let didWarnAboutDirectlyAssigningPropsToState ;
6768
6869if ( __DEV__ ) {
6970 didWarnAboutStateAssignmentForComponent = new Set ( ) ;
7071 didWarnAboutUninitializedState = new Set ( ) ;
7172 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set ( ) ;
7273 didWarnAboutLegacyLifecyclesAndDerivedState = new Set ( ) ;
74+ didWarnAboutDirectlyAssigningPropsToState = new Set ( ) ;
7375 didWarnAboutUndefinedDerivedState = new Set ( ) ;
7476
7577 const didWarnOnInvalidCallback = new Set ( ) ;
@@ -674,6 +676,20 @@ function mountClassInstance(
674676 instance . context = getMaskedContext ( workInProgress , unmaskedContext ) ;
675677
676678 if ( __DEV__ ) {
679+ if ( instance . state === newProps ) {
680+ const componentName = getComponentName ( ctor ) || 'Component' ;
681+ if ( ! didWarnAboutDirectlyAssigningPropsToState . has ( componentName ) ) {
682+ didWarnAboutDirectlyAssigningPropsToState . add ( componentName ) ;
683+ warningWithoutStack (
684+ false ,
685+ '%s: It is not recommended to assign props directly to state ' +
686+ "because updates to props won't be reflected in state. " +
687+ 'In most cases, it is better to use props directly.' ,
688+ componentName ,
689+ ) ;
690+ }
691+ }
692+
677693 if ( workInProgress . mode & StrictMode ) {
678694 ReactStrictModeWarnings . recordUnsafeLifecycleWarnings (
679695 workInProgress ,
0 commit comments