Skip to content

Commit

Permalink
Update prop-types in chapter 12
Browse files Browse the repository at this point in the history
  • Loading branch information
kay-is committed Sep 6, 2018
1 parent 1ec940a commit e5d7231
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions 12-component-refactor.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@

// The component has a simple props-interface
ViewBefore.propTypes = {
rooms: PropTypes.array.isRequired,
rooms: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string.isRequired,
people: PropTypes.number.isRequired
})).isRequired
}

// Now we switch out the implementation with something more complicated
Expand All @@ -66,15 +69,21 @@
}
// We keep the props-interface the same
ViewAfter.propTypes = {
rooms: PropTypes.array.isRequired,
rooms: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string.isRequired,
people: PropTypes.number.isRequired
})).isRequired
}

// We could also switch it with something more dynamic
var ViewDynamic = createReactClass({

// We still keep the props-interface the same
propTypes: {
rooms: PropTypes.array.isRequired,
rooms: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string.isRequired,
people: PropTypes.number.isRequired
})).isRequired
},

getInitialState: function() {
Expand Down Expand Up @@ -135,4 +144,4 @@ <h3>Dynamic refactor</h3>
</div>

ReactDOM.render(reactElement, document.getElementById("app"))
</script>
</script>

0 comments on commit e5d7231

Please sign in to comment.