Skip to content

Commit

Permalink
Move defaultProps example from lesson 06 to lesson 05
Browse files Browse the repository at this point in the history
  • Loading branch information
kay-is committed Aug 7, 2018
1 parent 4f6aa35 commit 1ec940a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 8 additions & 1 deletion 05-properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ <h2>{props.customData}</h2>
)
}

// Add the defaultProps (function-)property to set the defaults
// if nothing was provided by the user
MyComponent.defaultProps = {
customData: "default-data",
className: "default-class",
}

var reactElement = <MyComponent className="abc" customData="world"/>

// Which also works with an object and the spread (...) operator
Expand Down Expand Up @@ -48,4 +55,4 @@ <h2>{props.customData}</h2>
var renderTarget = document.getElementById("app")

ReactDOM.render(reactElement, renderTarget)
</script>
</script>
9 changes: 1 addition & 8 deletions 06-property-types.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ <h2>{props.customData}</h2>
customData: PropTypes.string,
}

// Add defaultProps (function-)property to set the defaults
// if nothing was provided by the user
MyComponent.defaultProps = {
customData: "default",
className: "default-class",
}

// This will show a warning in the console, because customData should be a string
var reactElement = <MyComponent customData={123}/>

Expand All @@ -50,4 +43,4 @@ <h2>{props.customData}</h2>
var renderTarget = document.getElementById("app")

ReactDOM.render(reactElement, renderTarget)
</script>
</script>

0 comments on commit 1ec940a

Please sign in to comment.