Skip to content

Instantly share code, notes, and snippets.

@haakenlid
Last active April 4, 2016 11:46
Show Gist options
  • Save haakenlid/1fc311af2bbd80364c91d77325d7e0f3 to your computer and use it in GitHub Desktop.
Save haakenlid/1fc311af2bbd80364c91d77325d7e0f3 to your computer and use it in GitHub Desktop.
Ultisnip for jsx stateless function with proptypes
global !p
from snippet_helpers import *
def expand_proptypes(props):
if not props:
return ''
pattern = '{}: React.PropTypes.any'
props = (prop.strip() for prop in props.split(','))
return ',\n '.join(pattern.format(prop) for prop in props)
endglobal
snippet jsx "define jsx dom" b
import React from 'react'
const ${1:`!p snip.rv = path_to_component_name(path, pascal_case_basename)`} = ({ $2 }) => (
<${4:div}>
${VISUAL}$5
</$4>
)
$1.propTypes = {
`!p snip.rv = expand_proptypes(t[2])`
}
$0
export default $1
endsnippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment