react-amphtml
Version:
Use amphtml components inside your React apps easily!
58 lines (50 loc) • 1.3 kB
JavaScript
;
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = require('react');
var React__default = _interopDefault(React);
var PropTypes = _interopDefault(require('prop-types'));
var __chunk_2 = require('../../constants.js');
var __chunk_3 = require('../../lib/contextHelper.js');
const AmpState = ({
children,
id,
src
}, context) => {
__chunk_3.default({
context,
extension: 'amp-bind'
});
if (src) {
return React__default.createElement("amp-state", {
id: id,
src: src
});
}
return React__default.createElement("amp-state", {
id: id
}, React__default.createElement("script", {
type: "application/json" // eslint-disable-next-line react/no-danger
,
dangerouslySetInnerHTML: {
__html: JSON.stringify(children)
}
}));
};
AmpState.propTypes = {
id: PropTypes.string,
children: PropTypes.object,
// eslint-disable-line react/forbid-prop-types
src: PropTypes.string
};
AmpState.contextTypes = {
[__chunk_2.CONTEXT_KEY]: PropTypes.shape({
addExtension: PropTypes.func.isRequired
})
};
AmpState.defaultProps = {
id: '',
children: null,
src: undefined
};
exports.default = AmpState;
//# sourceMappingURL=AmpState.js.map