From edda16284f88c87e65a82d05028d4dd2501181e3 Mon Sep 17 00:00:00 2001 From: Josh Perez Date: Tue, 14 Apr 2015 17:49:55 -0700 Subject: [PATCH] Add shouldComponentUpdate to AltContainer --- components/AltContainer.js | 6 ++++++ docs/components/altContainer.md | 16 ++++++++++++++++ test/store-listener-component-test.js | 15 +++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/components/AltContainer.js b/components/AltContainer.js index f529feae..1103834e 100644 --- a/components/AltContainer.js +++ b/components/AltContainer.js @@ -160,6 +160,12 @@ var AltContainer = React.createClass({ ) }, + shouldComponentUpdate: function () { + return this.props.shouldComponentUpdate + ? this.props.shouldComponentUpdate(this.getProps()) + : true + }, + render: function () { var children = this.props.children diff --git a/docs/components/altContainer.md b/docs/components/altContainer.md index 321598dc..2a1cc2d1 100644 --- a/docs/components/altContainer.md +++ b/docs/components/altContainer.md @@ -197,3 +197,19 @@ const flux = new Flux(); ``` Header, Body, and Footer will have the `flux` context passed down. + +## `shouldComponentUpdate` + +`shouldComponentUpdate` prop allows you to fine-tune your performance needs for AltContainer only rendering when absolutely necessary. + +This is a function that gets called with the props that your children will receive. You return a boolean depending on if you wish to re-render or not. + +```js + false}> +
+ +