I'm trying to use react-native-vector-icons with ES6 in React Native, but unfortunately I'm having trouble importing the icons. Their documentation still uses the old require statement, so I don't think it's helpful.
This is my import:
import {Ionicons} from './node_modules/react-native-vector-icons/Ionicons.js';
This is my usage:
<Ionicons name="ios-book" color="#4F8EF7" />
The error I receive is:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
It's clear that Ionicons is undefined, so I'm aware that fundamental about the import statement is wrong.
import Ionicons from 'react-native-vector-icons/Ionicons';
import {x} from 'abc'; translates to var x=require('abc').x, not to var x=require('abc').
So what about :
import * as Ionicons from './node_modules/react-native-vector-icons/Ionicons.js';
I ended up using an import statement as follows:
import {default as Icon} from '../node_modules/react-native-vector-icons/Ionicons';
This is because after I followed #Olivier's advice, I ended up with an object that contained a number of properties and I couldn't just use <Icon> as a component, but I discovered that <Icon.default> worked.
Thanks to all who answered!
Related
I am trying to use Input.Keys.A for example but I can't import that enum. Have the sam problem with ShapeRenderer and ShapeType.
using this
from com.badlogic.gdx import InputProcessor, Input, Input$Keys
doesn't work
trying this:
from com.badlogic.gdx import InputProcessor, Input, Keys
I get unresolved import. Why is there this strange $ sign. Input.Keys and ShapeRenderer.ShapeType doesn't work. can't even render a simple rectangle because of this.
I found a workaround.
to get enums from libgdx use Class.forName() insert the whole path to the enum.
here is an example for the ShapeRenderer$ShapeType
p = Class.forName("com.badlogic.gdx.graphics.glutils.ShapeRenderer$ShapeType").getEnumConstants()
if you do
print(p)
you get an array with the enums
use it like this
sr = ShapeRenderer()
sr.begin(p[2])
to use ShapeType.Filled for example
this approach should work with every enum
used it with com.badlogic.gdx.Net$Protocol to and it worked.
In short, how can I combine these two lines of code?
import * as php from './php';
import {str_replace, trim} from './php';
I can't find a syntax that works. I've tried things like
import {str_replace, trim}, * as php from './php';
N.B. this is ECMAScript 2015 (6th Edition, ECMA-262).
You cannot combine these in ES6 indeed. You can only use namespace imports or named imports together with a default import, but not with each other.
The solution is either to keep the two lines, or just use php.str_replace and php.trim everywhere in the code and drop the named imports.
I have a simple import statement:
import './dataMapper' as dataMap;
I am getting an error
Module build failed: SyntaxError: data.jsx: Unexpected token (1:22)
I can't seem to figure out why. If I just plain import without "as ...", it works.
According to at least this:
http://www.sitepoint.com/understanding-es6-modules/
it is the correct syntax.
It's not the correct syntax (and it's not on the page you linked either). You'll want to have a look at http://www.2ality.com/2014/09/es6-modules-final.html for a good reference.
Your code should be
import dataMap from './dataMapper'; // to import the default
or
import * as dataMap from './dataMapper'; // to import the module object
I'm working with babel-loader inside webpack for the first time, and I'm very new to ES6 as well. I'm trying to export a base class from one file and import it into another. Exporting and importing has worked fine throughout my file thus far, and I am just now hitting a problem with it for the first time while trying to create classes.
Here's what my code looks like:
BaseClient.js
export default class BaseClient {
// snip...
};
SessionClient.js
import BaseClient from './BaseClient';
// outputs "undefined":
console.log(BaseClient);
// throws "Uncaught TypeError: Super expression must either be null or a function, not undefined":
export default class SessionClient extends BaseClient {
// snip...
};
Am I doing something wrong? Is there any relevant information I'm missing from my question that's needed before diagnosing? Thanks!
Yeah, I met the issue as well. It's caused by circular reference between different files in very long reference chain.
Like following:
I have created a simple parser package called parseLine.
I have it in a package in my project.
In parseLine I have a class called "myParse".
I can import it just fine.
import parseLine.myParse.*;
But when I compile I get an error "1172:Definition parseLine.myParse could not be found.".
This is pretty basic I know but would appreciate any help anyone my be able to offer.
myParse is not a package, it is a class, so you are importing it incorrectly.
Basic structure of a package:
src / my / package / name / ClassName
To import ClassName, you would use this:
import my.package.name.ClassName;
or
import my.package.name.*;
In ClassName, it must have the following setup:
package my.package.name {
public class ClassName {
// class code goes here
}
}
As an additional tip, you should follow standard naming schemes for AS3.
Package names should be all lowercase. Even if it is multiple words. my.packagename is proper, whereas my.packageName is not.
Class names should be UppercaseCamelcase. So ClassName is proper, whereas className and classname are not
All objects, including functions, should be lowercaseCamelcase. So var someObject is proper, whereas var SomeObject is not (same for function doSomething() vs function DoSomething())
Constants should be UPPERCASE_UNDERSCORE_SEPARATED. So const SOME_CONSTANT_VALUE is proper, whereas const someConstantValue is not.
Not using those rules won't break anything, but they are the accepted standards in AS3 which makes your code easier to read and maintain in the future.