From ef6aa1ef4590be62d6c4be4b358c6a36bedad0ca Mon Sep 17 00:00:00 2001 From: Manas Date: Sat, 31 Oct 2015 15:29:48 +0530 Subject: [PATCH] Warns when muted props are passed. --- .../shared/reconciler/ReactCompositeComponent.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/renderers/shared/reconciler/ReactCompositeComponent.js b/src/renderers/shared/reconciler/ReactCompositeComponent.js index 4cb8633c91b92..585389421844f 100644 --- a/src/renderers/shared/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/reconciler/ReactCompositeComponent.js @@ -27,6 +27,7 @@ var emptyObject = require('emptyObject'); var invariant = require('invariant'); var shouldUpdateReactComponent = require('shouldUpdateReactComponent'); var warning = require('warning'); +var shallowEqual = require('shallowEqual'); function getDeclarationErrorAddendum(component) { var owner = component._currentElement._owner || null; @@ -147,6 +148,7 @@ var ReactCompositeComponentMixin = { // Initialize the public class var inst; var renderedElement; + var propsMutated; // This is a way to detect if Component is a stateless arrow function // component, which is not newable. It might not be 100% reliable but is @@ -195,6 +197,15 @@ var ReactCompositeComponentMixin = { Component.displayName || Component.name || 'Component' ); } + + propsMutated = !shallowEqual(inst.props, publicProps); + if (propsMutated) { + warning( + propsMutated, + 'Mutated props not allowed in %s(...)', + Component.displayName || Component.name || 'Component' + ); + } } // These should be set up in the constructor, but as a convenience for