Comments (11)
I'll change it to regular CJS to simplify it.
The original reasoning is that you'll most likely be doing some transpiling for the browser and probably for the server too since some features don't run on latest node. If you're transpiling then you'll probably be either using import
on the server, or you'll figure out how to transpile export default
into module.exports
with some plugin, maybe this one?
These are too many assumptions though. :) Thanks for bringing it up.
from hypernova.
Yep, I did transpile with babel and react + es2015 presents, this what I've got:
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _hypernovaReact = require('hypernova-react');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function MyComponent(props) {
return _react2.default.createElement(
'div',
null,
'Hello, ',
this.props.name,
'!'
);
}
exports.default = (0, _hypernovaReact.renderReact)('MyComponent.js', MyComponent);
And server side rendering is all I care about and I'd be getting my components in es6/jsx so compiling will be part of the deploy process.
from hypernova.
I'm actually using just plain old CJS in the simple example since that's the quickest way to get something working:
I'll be putting up a more complex example: routing, state management, etc soon.
from hypernova.
One more question, about that example:
function MyComponent(props) {
return <div>Hello, {this.props.name}!</div>;
}
You're passing props
object, but using this.props
. :)
from hypernova.
Will check your example, thanks.
from hypernova.
@alexindigo where is that at? That's a bug.
from hypernova.
I see you fixed it here, but old version is still on npm:
from hypernova.
Playing more and with your updated example, I noticed that onClick
handler gets lost.
component:
import React from 'react';
import { renderReact } from 'hypernova-react';
function MyComponent(props) {
return <div onClick={() => alert('Click handlers work.')}>Hello, {props.name}!</div>;
}
export default renderReact('MyComponent.js', MyComponent);
Compiled:
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _hypernovaReact = require('hypernova-react');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function MyComponent(props) {
return _react2.default.createElement(
'div',
{ onClick: function onClick() {
return alert('Click handlers work.');
} },
'Hello, ',
props.name,
'!'
);
}
exports.default = (0, _hypernovaReact.renderReact)('MyComponent.js', MyComponent);
Output:
{
"success": true,
"error": null,
"results": {
"MyComponent.js": {
"name": "MyComponent.js",
"html": "<div data-hypernova-key=\"MyComponentjs\"><div data-reactroot=\"\" data-reactid=\"1\" data-react-checksum=\"1633367769\"><!-- react-text: 2 -->Hello, <!-- /react-text --><!-- react-text: 3 -->Alex<!-- /react-text --><!-- react-text: 4 -->!<!-- /react-text --></div></div>\n<script type=\"application/json\" data-hypernova-key=\"MyComponentjs\"><!--{\"theseAreProps\":true,\"name\":\"Alex\",\"someOtherProps\":[\"one\",\"two\",\"three\"]}--></script>",
"meta": {},
"duration": 9.820868,
"statusCode": 200,
"success": true,
"error": null
}
}
}
onClick
is gone, not sure if it's a feature or a bug.
from hypernova.
And one more thing, it's not clear to me (yet),
why I need to have import { renderReact } from 'hypernova-react';
as part of the component, is it different from the built-in React method?
Thank you.
from hypernova.
I see, it doesn't really renders it, more like priming for the hypernova usage:
function (props) {
var contents = _server2['default'].renderToString(_react2['default'].createElement(component, props));
return (0, _hypernova.serialize)(name, contents, props);
}
from hypernova.
@alexindigo ah yes, npm has the old README. When I publish a next version to npm the README will be updated there as well.
As for onClick
handler being "lost", React doesn't include any event handlers in the markup itself, that all lives in the code which is also included on the page and runs on the page.
The markup that you're producing is just the server-rendered HTML that is displayed to the user. Once you're on the browser with the JS loaded the React component will become "active" which will enable any event handlers and run componentDidMount
on your components.
from hypernova.
Related Issues (20)
- An in-range update of glob is breaking the build 🚨 HOT 2
- Example of async component fetching
- createApplication in docs but not released HOT 4
- More details about server requirements for production HOT 1
- [Question] Runtime loading/unloading modules HOT 2
- Proper source map support for development mode HOT 8
- Ruby version in example is ambiguous HOT 3
- An in-range update of eslint-plugin-import is breaking the build 🚨 HOT 2
- [Question] Load application on demand showing a pre loading
- An in-range update of rimraf is breaking the build 🚨 HOT 3
- CSS support? HOT 12
- Custom attributes on Hypernova DOM container HOT 1
- Encode closing Tag HOT 8
- Assets support
- An in-range update of eslint-plugin-import is breaking the build 🚨 HOT 3
- This project is no longer maintain? HOT 4
- An in-range update of in-publish is breaking the build 🚨 HOT 1
- Loadable Component integration
- Will this work with rails 7.x
- missing `.finally()` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hypernova.