title: ReactJS: How can I have a more modular use of prop types & shapes for objects?
body: <p>I like to explicitly specify all my prop types for every class.</p>
  
  <pre><code>React.createClass({
    propTypes: {
      optionalArray: React.PropTypes.array,
      optionalBool: React.PropTypes.bool,
  ...
  </code></pre>
  
  <p>This is from reading reusable components: <a href="https://facebook.github.io/react/docs/reusable-components.html" rel="noreferrer">https://facebook.github.io/react/docs/reusable-components.html</a></p>
  
  <p>However, what if I have a very common object that I use in many classes? For example:</p>
  
  <pre><code>var MemoryForm = React.createClass({
    propTypes: {
      memory: React.PropTypes.shape({
        memoryID: React.PropTypes.number,
        content: React.PropTypes.string,
        date: React.PropTypes.object,
        dateStr: React.PropTypes.string,
        note: React.PropTypes.string
      }).isRequired,
      ...
  
  var MemoriesArea = React.createClass({
    propTypes: {
      // The initial memory to fill the memory form with.
      formMemory: React.PropTypes.shape({ // &lt;== shape used again
        memoryID: React.PropTypes.number,
        content: React.PropTypes.string,
        date: React.PropTypes.object,
        dateStr: React.PropTypes.string,
        note: React.PropTypes.string
      }).isRequired,
      // ...
  
  
  
  var Playground = React.createClass({
    getInitialState: function() {
      var initVars = {
        // The initial memory to fill the memory form with.
        formMemory: {  // &lt;== shape is used again.
          memoryID: 0,
          content: "",
          date: null,
          dateStr: "",
          note: ""
        }
      };
      return initVars;
    }
    //...
  </code></pre>
  
  <p>Here, I use the 'memory' shape very frequently in the prop types for various classes, as well as in some initializations. How can make this more DRY - i.e., less code duplication, so a change to this object shape will be more maintainable in the future?</p>