React Native 中不同类型的导入?

Different type of import in React Native?

在 React Native 中,我们必须通过以下方法导入包。

  1. 从'react-native-router-flux'导入{操作};
  2. 从 'react-native-push-notification' 导入 PushNotification;

这些导入语句有什么不同?

当您像这样导出 components/things 时

export class Foo extends Component {…

你必须像这样导入它

import {Foo} from './foo.js'

当您导出为默认值时,就像这里一样

export default class Bar extends Component {…

你可以这样导入

import Bar from './bar.js'

当然,您可以每个文件只有一个默认导出。

默认导出

默认的导出方式如下:

const student={
  name: 'Sam'
}
export default student;

并且导入为

import student from './student.js'

import std from './student.js'

接收文件中的名称由您决定。只能有一个默认导出。

命名导出

命名导出完成如下:

export const anyFunc = () => {...}

export const anyValue = 10;

导入为:

import { anyFunction } from './anyfile.js'
import { anyValue } from './anyfile.js'

每个文件可以有多个命名导出。 导入您想要的特定导出并将它们括在大括号中。 导入模块的名称必须与导出模块的名称相同。