Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rt-import syntax question #228

Open
shiefra opened this issue Jul 21, 2017 · 1 comment
Open

rt-import syntax question #228

shiefra opened this issue Jul 21, 2017 · 1 comment

Comments

@shiefra
Copy link

shiefra commented Jul 21, 2017

What is the difference between <rt-import name="TagName" from "module_name"> and <rt-import name="*" as="TagName" from "module_name"> ?

For some module, I tried first one and I got the error message like below.

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Calendar3`

After some googling I tried second one, and then It works well.
Can anybody explain the difference between first and second one?

@nippur72
Copy link
Contributor

the first is rendered to a named import:

import { TagName } from "module_name";  // ES6 syntax
const TagName = require("module_name").TagName;  // commonjs syntax

the latter is rendered to a "module as a whole" import (can't remember how exactly it's called):

import * as TagName from "module_name";  // ES6 syntax
const TagName = require("module_name");  // commonjs syntax

To understand which to use, you should know how what you are importing was exported in the first place (this applies generally, not just for react-templates).

The only thing you should be aware is that react-templates itself does export as a "whole", so if you are importing from react-templates (stateless components or stateful render functions) you should use the latter syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants