Where to import React-Bootstrap components from? - react-bootstrap

I am using React-Bootstrap version 1.0.0-beta.10.
Whenever I want to use a component, for example Alert, I will get three import options from the IDE to choose from:
"react-bootstrap"
"react-bootstrap/Alert"
"react-bootstrap/es/Alert"
Which of them should I use and why?

Yes. We have multiple options to import a component.
When importing directly from react-bootstrap you need to import as,
import {Alert} from `react-bootstrap`;
Because Alert component is exported as named export.
If you expand the react-bootstrap folder from node_modules folder, you will see multiple folders and files.
The files directly available in react-bootstrap folder are based on ES5.
When I say based on ES5 means, the required package for this component are imported like this,
var _extends2 = _interopRequireDefault(require("#babel/runtime/helpers/extends"));
and you can import component as,
import Alert from `react-bootstrap/Alert`;
Because Alert component is exported as default export.
The files available in es folder are based on ES6.
When I say based on ES6 means, the required package for this component are imported like this,
import _extends from "#babel/runtime/helpers/esm/extends";
and you can import component as,
import Alert from `react-bootstrap/es/Alert`;
Because Alert component is exported as default export.

You must have to change your codebase.
react-bootstrap doesn't have a default export, so the default import syntax cannot be used in this case.
You can do the following though:
import * as ReactBootstrap from 'react-bootstrap';
And then, you can use the Alert component.

Related

import yaml file with svelte

Svelte can natively import json file
how to make this possible with a yaml file?
<script>
import data from 'data.yml'
console.log(data)
</script>
Svelte does not do anything. It all depends on the bundler/build tools, which usually support things like JSON.
If you want to import YAML, you need a plugin/loader for whatever build system you are using, and if none exist, you can write your own.

Is there any efficiency issue in duplicated importing in vue.js

I do refactoring some vue code And find duplication like below;
- main.ts
import BootstrapVue from 'bootstrap-vuew';
Vue.use(BootstrapVue);
I know that if main.ts do 'import bootstrap-vue' then other vue file use bootstrap component without importing.
But my co-worker do this meaningless imporing on every vue component.
So i Wonder that is this duplication has any critical efficiency issue?
If yes, it related to velocity of rendering?
Imports themselves aren't a problem. A module is evaluated and included into a bundle only once. It's discarded in production build if imported values aren't used in modules that import them.
It's Vue.use that makes it different. Imported plugin won't be discarded because it's used. A plugin can do side effects that should be applied only once and should have a safeguard against multiple installation. The plugin in question has such safeguard, so this introduces no problems except several bytes of unnecessary code per module.
The necessity of this is doubtful. Vue plugins affect global application behaviour. Vue.use needs to be used only once per plugin, this is commonly done in entry point, but can be done in feature modules as well, the latter can specify their own plugin dependencies for decoupling purposes. It doesn't make sense to use Vue.use in each module where library components are used. Instead they can import components per need basis, this allows to not include the whole library, considering that there's no plugin installation anywhere in the application.
So it's either installing a plugin once or several times globally per application or feature module:
import BootstrapVue from 'bootstrap-vue';
Vue.use(BootstrapVue)
Or using a subset of library locally as many times as needed:
import { DropdownPlugin } from 'bootstrap-vue';
Vue.use(DropdownPlugin)
And/or importing all used components locally as many times as needed:
import { BDropdown, BDropdownItem, ... } from 'bootstrap-vue';
export default {
components: {
BDropdown, BDropdownItem, ...
}
}
It always depends on a library if it's supposed to be used one way or another.
Importing a library in global "main.ts" enough to use in any component throughout the application. But importing multiple times in all components can cause large size build file. So, it's better to use only one import of the library in "main.ts".

import platform specific componet to a module in nativescript angular

I have a component that I split into platform specific files
ex.component.ios.ts and ex.component.android.ts
my question is how to import it into the module because using just ex.component gives me an error
thanks.
i think it can be resolved using a ex.d.ts file that has
export const ex: any;

es6 module import of d3 4.x fails

TL;DR: The documented way to import d3 into es6 modules fails. What is the correct way to do this? My guess is the documentation assumes I use a workflow that resolves these problems
Details:
The readme for d3 4.x says:
D3 is written using ES2015 modules. Create a custom bundle using Rollup, Webpack, or your preferred bundler. To import D3 into an ES2015 application, either import specific symbols from specific D3 modules:
import {scaleLinear} from "d3-scale";
Or import everything into a namespace (here, d3):
import * as d3 from "d3";
Yet when I yarn add d3 and use a es6 script tag, this fails to work:
<html>
<head>
<title>D3</title>
</head>
<body>
<script type="module">
import * as d3 from "./node_modules/d3"
</script>
</body>
</html>
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Replacing the import with:
import * as d3 from "./node_modules/d3/index.js"
..gives this error:
Uncaught TypeError: Failed to resolve module specifier 'd3-array'
#jimmont is correct: importing the module form of d3 packages does not work without local building due to the "bare" imports. These can be resolved by the CDN's D3 uses, in particular unpkg.com. Here's the story.
It turns out d3 uses package.json to allow it to export two formats from a single source, npm itself. To do so, it uses the module: field.
The easiest way to access either all of d3, or a submodule/repo (there are 30 of them!) unpkg is ideal:
A dashboard to the repo: https://unpkg.com/d3/
The current umd/iife: https://unpkg.com/d3
The current collection of all modules: https://unpkg.com/d3?module
To import all of d3:
import * as d3 from 'https://unpkg.com/d3?module'
To import sub-modules:
import * as selection from 'https://unpkg.com/d3-selection?module'
es6 and es2015 modules will not work with d3 because d3 has chosen to use rollup instead. You are seeing this error because the module cannot be resolved as specified in the file "./node_modules/d3/index.js" which has lines like export {default as ascending} from "./src/ascending"; which are missing the real file name which ends with '.js'. So in other words all these entries are mis-configured to not support native modules in browsers or Nodejs.
you can either use rollup or make all the text substitutions yourself using a script or manually. I use a perl one-liner because I dislike rollup and the extra dependencies were breaking between node 8 and node 10. it is unbelievably strange that this is necessary but I also haven't been supporting a kitchen sink of module loaders.
import * as d3 from "./node_modules/d3-something/index.js"
which has content like export {default as something} from './src/thing'. because these files do not use the natively supported syntax with a full relative path (it's missing the actual file extension), it won't work without rollup or whatever making these corrections. multiple popular projects have made this same decision to require extra modules to work properly and forego native support.
see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

Swift - Import my swift class

This question is asked several times, but I can't find the right solution for my problem. I'm trying to import my Player.swift class in my MainScene.swift (I've used Cocos2D - SpriteBuilder to setup the project; Now using Xcode).
This is my folder structure:
I've tried to use import Player; and import Player.swift;, but when I tried I got this error: No such module 'Player.swift'
How do I import it correctly?
Thanks!
By the way, I'm a beginner in Swift, so don't expect that I know all of the terms
You don't need to explicitly import files in Swift as they are globally available through the project. If you want to access the methods or properties of Player class, you can directly make object of Player class in MainScene.Swift file and can access to it.
e.g var objPlayer = Player()
There is no need to import swift classes to use in other swift classes.
They are available to use automatically.
In Swift you can only import module, e.g. any framework like UIKit, MapKit as below. You cannot import swift classes.
import UIKit
import MapKit
Just make sure its selected to use in target in which your are trying to use.
Check below images for more idea.
In this image my HomeViewController.swift is selected to use in AutolayoutDemo module.
In below image I have unchecked AutolayoutDemo module for the class DetailsViewController.swift.
So now onwards when I will try to use the DetailsViewController compiler will give me error as below image in HomeViewController.
When it comes to Swift imports, there are two cases:
1) The type to import is in the module
In this case, no import statement is needed. As long as the type is not private or fileprivate, you can directly access it.
2) The type to import is outside of the module
You can import an entire module using:
import ModuleName
If you only want to import a specific type or function from the module, you can do this using the following format:
import kindOfThing ModuleName.Type
where kindOfThing is class/struct/func/etc...
A much deeper exploration of this can be found on NSHipster here.
Check if the class is added to your iOS target in right Pane or not .

Resources