How to use React.js to render server-side template on Sails.js? How to use React.js to render server-side template on Sails.js? reactjs reactjs

How to use React.js to render server-side template on Sails.js?


Your problem isn't with your component itself, it's how you're exporting it from your module.

When using just export you need to import your module like this.

import {Auth} from 'auth';

Just using export allows for exporting more than 1 thing from your module.

// My Module.export function a(x) {    console.log('a');}export function b(x, y) {    console.log('b');}import { a, b } from 'myModule';

or you can use import * from 'myModule';This is called a named export.

What your use case begs for is the use of export default which allows a single object to be exported from your module.

export default class Auth extends React.Component {}

Thus letting you import your module as a single object without curly braces.

import Auth from 'auth';

Then you need to render using either use JSX syntax React.renderToString(<Auth />); orReact.createElement(Auth);

You can read all on how modules in ECMA Script 6 works here