Skip to content

Instantly share code, notes, and snippets.

@queckezz
Last active December 2, 2015 18:59
Show Gist options
  • Save queckezz/009017e4e86fd927d87f to your computer and use it in GitHub Desktop.
Save queckezz/009017e4e86fd927d87f to your computer and use it in GitHub Desktop.
react better createElement (temporary until r-dom)
import { createElement } from 'react'
const isChildren = arr => typeof arr == 'string' || Array.isArray(arr)
const create = (tag, props, children) => {
if (Array.isArray(children)) {
return createElement(tag, props, ...children)
} else {
return createElement(tag, props, children)
}
}
const h = (tag, ...rest) => {
const [props, children] = rest
// h(tag, {}) or h(tag, [])
if (rest.length == 1) {
if (isChildren(props)) {
// children = props
return create(tag, {}, props)
}
return createElement(tag, props)
}
// all params h(tag, {}, [])
return create(tag, props, children)
}
export default h
import {
createStore,
applyMiddleware
} from 'redux'
import logger from 'redux-logger'
const createStoreWithMiddleware = applyMiddleware(
logger()
)(createStore)
export default createStoreWithMiddleware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment