Created
November 30, 2016 17:23
Revisions
-
jvans1 created this gist
Nov 30, 2016 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ //Normal Approach: const NameComponent = React.createClass({ propType: { name: React.propTypes.String }, render: function(){ return <h1> {{ this.props.name }} </h1> } }) React.createClass({ render: function(){ return <div><NameComponent name="James" /></div> } }) //But you can also do: function displayName(name){ return <h1> {{ name }} </h1> } React.createClass({ render: function(){ return <div>{{ displayName("James") }}</div> } }) //With this second example we achieve a couple of things //1. Do not run unnecessary react lifecycle events in the second example //2. Communicate very clearly the intention of the component //3. Prevent other developers from haphazardly making this component more complex than necessary //4. Making this into a regular component isn't hard but it's enough extra work to make you pause and rethink your design.