React Elementary
React Elementary is a small library of helper functions for creating React elements and handling props using plain JavaScript (no JSX).
Installation
npm install react-elementary
Usage
Importing
; ; // or ; elementary; // or ; ;
createElement
Use this function just like React.createElement
, except that props are
optional. Also, the innerHtml
prop is rewritten into
dangerouslySetInnerHtml
. You can also create a custom createElement
which
does other props mappings by using mapElementPropsWith
from the
react-elementary/lib/createElement
module (it's not exported from the index
module).
; ; { return ;}
createFactory
Similar to React.createFactory
. Creates a factory function for creating
multiple elements of the same type.
; const div = ; { return ;}
createFactories
Takes an object of ReactClass
or strings, and outputs an object of factory
functions.
; const factories = ; { return factories;}
elements
An object of common element factories, just like React.DOM
.
; const div em h1 p = elements; { return ;}
mapIntoArray
Takes an iterable collection (like Immutable.List
), and a mapping function,
returning an array.
This is deprecated and will be removed in a later version. It's not really needed since React can handle non-array iterables.
; const Article = ;const div = elements; { return ;}
mergeProps
Takes any number of objects, and merges them. The default function merges the
className
property with the classnames
module. You can also create a custom
merge function by using createCustomMerge
from the
react-elementary/lib/mergeProps
module.
; const div = elements; { // If the provided props are { className: 'foo', id: 'foo' } return ; // then the returned element has the props { className: 'foo bar', id: 'bar' }}
Legal
Copyright © 2016 Reidar Djupvik
Licensed under the MIT license. See the LICENSE
file for details.