I'd like to use Express, pg and react for my project. But react give me some problems.
index.js
var express = require('express');
var server = express();
var path = require('path');
var app = require('./app/app.js');
server.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
server.listen(3000, function () {
console.log("server is running on port 3000!");
});
var connexionDB = require('./db/connexionAvecPg');
app.js
var react = require('react');
var {render} = require('react-dom');
var App = react.createClass({
render: function () {
return(
<div>
<p>test</p>
</div>
);
}
});
render(
<App/>,
document.getElementById('root')
);
(Yes it's ES5, but i have my reason for using it instead of ES6-7)
What's wrong with my code? did i forget something? Thx for your time.
---\ EDIT /---
After Ming Soon's answer, I tried this:
app.js
var React = require('react');
var ReactDOM = require('react-dom');
class App extends React.component{
render() {
return React.createElement('div', null, 'Test');
}
};
ReactDOM.render(
React.createElement(App, null),
document.getElementById('root')
);
But i have this:
/home/josue/im-expressandpg/app/app.js:14
class App extends React.component{
^
TypeError: Class extends value undefined is not a constructor or null
---\ EDIT 2 /---
Thx to PSo i saw my mistake. I changed this:
class App extends React.component{
To this:
class App extends React.Component{
When i exec:
/home/josue/im-expressandpg/app/app.js:17
document.getElementById('root')
^
ReferenceError: document is not defined
If i add this:
var document = require('./../public/index.html');
I get:
/home/josue/im-expressandpg/public/index.html:1
(function (exports, require, module, __filename, __dirname) { <!doctype html>
^
SyntaxError: Unexpected token <