Last active
          September 21, 2016 17:29 
        
      - 
      
- 
        Save kevinSuttle/fb3d4b33c83e091e7f980dda9ff8df8e to your computer and use it in GitHub Desktop. 
    Flow, defaultProps, and wrapper classes
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // @flow | |
| import React from 'react'; | |
| require('./Icon.css'); | |
| import * as Glyphs from './Glyphs.jsx'; | |
| export type IconProps = { | |
| glyph:string, | |
| className?: string, | |
| title?: string, | |
| width?: string, | |
| height?: string, | |
| }; | |
| export default class Icon extends React.Component { | |
| static defaultProps = { | |
| 'className': 'icon', | |
| 'width': '16', | |
| 'height': '16', | |
| } | |
| constructor(props:IconProps){ | |
| super(props); | |
| } | |
| render(){ | |
| return( | |
| <svg | |
| id="icon" | |
| className={this.props.className} | |
| viewBox={`0 0 ${this.props.width} ${this.props.height}`} | |
| aria-labelledby="title" | |
| preserveAspectRatio="xMidYMid meet" | |
| > | |
| <title id={this.props.title}>{this.props.title}</title> | |
| {Glyphs[this.props.glyph] || null} | |
| </svg> | |
| ) | |
| } | |
| } | 
Ah, I had that almost exactly earlier. The one thing that I feel is a little too magic is not explicitly showing what the propTypes are in an HOC. If I'm someone consuming this, it's like an undocumented API, right?
Does const IconButtonProps = Object.assign(...ButtonProps, ...IconProps) work?  I've never known for sure whether import/export type statements actually create normal JS variables.  ButtonProps & IconProps should work though
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
So I think what you did is totally fine, just don't need to define prop types since you have flow annotations now. Common way is just to write out the input prop types explicitly: