I am using React and hypernova (with php bindings) in order to perform server-side rendering of some React components. Below is my following test component and the response from hypernova.
Test.js
import React from 'react';
import { renderReact } from 'hypernova-react';
class Test extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<p onClick={() => alert('hey')}>click me</p>
);
}
}
export default renderReact('Test', Test);
hypernova response
WF\Hypernova\JobResult Object
(
[error] =>
[html] =>
<div data-hypernova-key="Test" data-hypernova-id="e5af0b95-2a31-4ce4-8e36-808605fd4115">
<p data-reactroot="">click me</p>
</div>
<script type="application/json" data-hypernova-key="Test" data-hypernova-id="e5af0b95-2a31-4ce4-8e36-808605fd4115">
<!--{"prop1":"a","prop2":"b"}-->
</script>
[success] => 1
...
)
As shown above, props
are being successfully passed, but the onClick
handler is nowhere to be found. However, it definitely exists in the transpiled code.
bundle.js
// code before and after class omitted for brevity
var Test = function (_React$Component) {
_inherits(Test, _React$Component);
function Test(props) {
_classCallCheck(this, Test);
return _possibleConstructorReturn(this, (Test.__proto__ || Object.getPrototypeOf(Test)).call(this, props));
}
_createClass(Test, [{
key: 'render',
value: function render() {
return _react2.default.createElement(
'p',
{ onClick: function onClick() {
return alert('hey');
} },
'click me'
);
}
}]);
return Test;
}(_react2.default.Component);
exports.default = (0, _hypernovaReact.renderReact)('Test', Test);
The only thing I've been able to find on the issue has been in the github issue tracker in which someone complains about the same thing, but apparently there isn't supposed to be an event handler on the <p>
tag; it is supposed to exist in code delivered by React. I have also tried assigning a click handler using a class property with/without arrow notation (explicitly binding in the constructor in the latter case). I have added a <script>
tag with my bundled React code, but that doesn't appear to make a difference.
Is this a bug, or am I doing something wrong?