A
A
Alexander Knyazev2016-08-20 17:59:43
JavaScript
Alexander Knyazev, 2016-08-20 17:59:43

How to add script to jsx code?

I'm starting to write an application in Express with pre-rendering on the server.
Sketched app.js:

var http = require('http');
var express = require('express');
var React = require('react');
var ReactDOMServer = require('react-dom/server');

//component with basic layout
var DefaultHtml = require('./src/components/default');

var bodyParser = require('body-parser');


var config = require('./config');

var app = express();


// Using bodyParser middleware
app.use( bodyParser.json() );

http.createServer(app).listen(config.serverPort);

app.get('/', function (req, res) {
  
  var html = ReactDOMServer.renderToString(<DefaultHtml />);
  console.log(html);
  res.status(200);
    res.send(`<!doctype html>${html}`)
});

The code of the default module that exports the DefaultHtml component
class DefaultHtml extends React.Component {
 	render() {
    return <html>
    		<head>
    			<title>Hello</title>
    		</head>
    		<body>
    			<h1>Hello</h1>
    		</body>
    </html>
  	}
}

module.exports = DefaultHtml;

The question is: how can I add js scripts, jquery, for example, to the head tag in the DefaultHtml component? Regular script tag doesn't fit

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question