UNPKG

react-bind-properties

Version:

Add native property bindings to React for use with custom elements

36 lines (31 loc) 1.35 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import React from 'react'; export default function jsx(type, props) { var newProps = _extends({}, props); if (typeof type === 'string') { newProps.ref = function (element) { // merge existing ref prop if (props && props.ref) { if (typeof props.ref === 'function') { props.ref(element); } else if (typeof props.ref === 'object') { props.ref.current = element; } } if (element) { if (props && props.bindProps && typeof props.bindProps === 'object') { Object.entries(props.bindProps).forEach(function (_ref) { var key = _ref[0], value = _ref[1]; element[key] = value; }); element.removeAttribute('bindProps'); } } }; } for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { children[_key - 2] = arguments[_key]; } return React.createElement.apply(null, [type, newProps].concat(children)); }