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

 ̄綄美尐妖づ 提交于 2019-12-04 05:03:21

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 />); or React.createElement(Auth);

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!