Last active
March 6, 2017 19:50
-
-
Save jacob-beltran/ae63069d95831fb49e59e74eb7ddbd11 to your computer and use it in GitHub Desktop.
Revisions
-
jacob-beltran revised this gist
Mar 6, 2017 . No changes.There are no files selected for viewing
-
jacob-beltran created this gist
Mar 3, 2017 .There are no files selected for viewing
This file contains hidden or 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,32 @@ /* Sometimes a fallback value or object may be created in the render function ( or prop value ) to avoid undefined value errors. In these cases, it's best to define the fallbacks as a constant external to the component instead of creating a new literal. /* /* Bad */ render() { let thingys = []; // If this.props.thingys is not defined a new array literal is created above. if( this.props.thingys ) { thingys = this.props.thingys; } return <ThingyHandler thingys={ thingys }/> } /* Bad */ render() { // This has functionally the same outcome as the above example. return <ThingyHandler thingys={ this.props.thingys || [] }/> } /* Good */ // Declare outside of component const NO_THINGYS = []; render() { return <ThingyHandler thingys={ this.props.thingys || NO_THINGYS }/> }