这是一个普通的ES6问题,但我在React Native的上下文中遇到过。基本的问题是我想重写一些通常使用我自己的组件从“react-native”模块导入的组件。我这样做的方法如下所示:扩展命名空间JS导入
,而不需要组件与import { Text, View, etc } from 'react-native'
需要他们这样的:import { Text, View, etc } from './ui_components'
其中ui_components.js
看起来像:
export * from 'react-native'
问题是,我如何将自己的组件添加到此导出?理想情况下,我会能够通过做这样的事情,以增加他们在ui_components.js
:
import * as RN from 'react-native'
RN.Text = myTextComponent
RN.View = myViewComponent
export * from RN
但是这完全不是那么回事。有任何想法吗?
RN对象应该是只读的,您不能对其进行修改。 – estus
相关:http://stackoverflow.com/questions/32558514/javascript-es6-export-const-vs-export-let – Gerrit0