From 256e0bf6dfc630f2ca28cce488aaf353c7bf4c1e Mon Sep 17 00:00:00 2001 From: Jared Forsyth Date: Tue, 10 Dec 2013 11:50:44 -0700 Subject: [PATCH] rename this tip to be less confusing Using props to initialize state is completely fine; the issue is using state as a "cache" for values calculated based off of props. This title makes it more clear. --- tips/10-props-in-getInitialState-as-anti-pattern.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tips/10-props-in-getInitialState-as-anti-pattern.md b/tips/10-props-in-getInitialState-as-anti-pattern.md index 097fbc718..a9551ce36 100644 --- a/tips/10-props-in-getInitialState-as-anti-pattern.md +++ b/tips/10-props-in-getInitialState-as-anti-pattern.md @@ -1,6 +1,6 @@ --- id: props-in-getInitialState-as-anti-pattern -title: Props in getInitialState Is an Anti-Pattern +title: Using state to cache calculations is an antipattern layout: tips permalink: props-in-getInitialState-as-anti-pattern.html prev: componentWillReceiveProps-not-triggered-after-mounting.html @@ -11,7 +11,7 @@ next: dom-event-listeners.html > > This isn't really a React-specific tip, as such anti-patterns often occur in code in general; in this case, React simply points them out more clearly. -Using props, passed down from parent, to generate state in `getInitialState` often leads to duplication of "source of truth", i.e. where the real data is. Whenever possible, compute values on-the-fly to ensure that they don't get out of sync later on and cause maintenance trouble. +Using state to cache values calculated from props (for example in `getInitialState`) often leads to duplication of "source of truth", i.e. where the real data is. Whenever possible, compute values on-the-fly to ensure that they don't get out of sync later on and cause maintenance trouble. Bad example: