BVB Source Codes

prettier Show proptype_objectOf.js Source code

Return Download prettier: download proptype_objectOf.js Source code - Download prettier Source code - Type:.js
  1. /* @flow */
  2.  
  3. var React = require('react');
  4. var Example = React.createClass({
  5.   propTypes: {
  6.     obj: React.PropTypes.objectOf(React.PropTypes.number).isRequired
  7.   },
  8. });
  9.  
  10. var ok_empty = <Example obj={{}} />
  11. var ok_numbers = <Example obj={{foo: 1, bar: 2}} />
  12.  
  13. var fail_missing = <Example />
  14. var fail_not_object = <Example obj={2} />
  15. var fail_mistyped_props = <Example obj={{foo: "foo"}} />
  16.  
  17. /* Since the `number` proptype argument is not required, React will actually
  18.    allow `null` and `undefined` elements in the `obj` prop, but Flow has
  19.    currently ignores the innter prop type's required flag. */
  20. var todo_required = <Example obj={{p:null}} />
  21.  
  22. var OptionalExample = React.createClass({
  23.   propTypes: {
  24.     obj: React.PropTypes.objectOf(React.PropTypes.number),
  25.   }
  26. });
  27.  
  28. (<OptionalExample />); // OK
  29. (<OptionalExample obj={{p:0}} />); // OK
  30. (<OptionalExample obj={{p:""}} />); // error: string ~> number
  31.  
  32. var AnyExample = React.createClass({
  33.   propTypes: {
  34.     obj: React.PropTypes.objectOf((0:any)), // OK
  35.   },
  36. });
  37.  
  38. (<AnyExample obj={0} />); // error: still needs to be an object
  39. (<AnyExample obj={{p:0}} />); // OK
  40.  
  41. var InvalidExample = React.createClass({
  42.   propTypes: {
  43.     obj: React.PropTypes.objectOf(0), // error: number not a prop type
  44.   },
  45. });
  46.  
downloadproptype_objectOf.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top