ecmascript 6 - ReactJS - props or propTypes? -
when i'm reading props open source, see use of props
, proptypes
declare properties obtained parent. difference between two? 1 should used?
for example:
props source code
export default class app extends component { props: { children: children }; render() { return ( <div> {this.props.children} </div> ); } }
proptypes source code
export default class board extends component { static proptypes = { getlists: proptypes.func.isrequired, movecard: proptypes.func.isrequired, movelist: proptypes.func.isrequired, lists: proptypes.array.isrequired, } ... }
props actual properties sent react class. proptypes used define properties class supposed receive. should use both more props
nice thing proptypes helps ensure correct type sent every property since define should be... meaning receive console warning saying invalid prop type passed component. more proptypes
Comments
Post a Comment