反应的本机代码可内联,但在导入时不起作用

问题描述 投票:0回答:1

以下代码在react native 0.61.5中可以正常工作。

// userApplication/screens/UserScreen.js

import React, {Component} from 'react';
import { Button } from "./../components/arComponents";

class UserScreen extends React.Component {
    let COLORS = {
        INFO: '#11CDEF',
    }

    render{
        return (
            <>
                <Button style={{ backgroundColor: COLORS.INFO }} >Connect</Button>
            </>
        )
    }
}

但是,当尝试导入完全相同的对象时,它不起作用。

我有以下内容:

// userApplication/screens/UserScreen.js

import React, {Component} from 'react';
import { Button } from "./../components/arComponents";
import { argonTheme } from "./../constants";  //This line changed from code above

class UserScreen extends React.Component {
    let COLORS = {
        INFO: '#11CDEF',
    }

    render{
        return (
            <>
                <Button style={{ backgroundColor: argonTheme.COLORS.INFO }} >Connect</Button>  //This line changed from code above
            </>
        )
    }
}

这是常量文件夹中的index.js文件:

//  userApplication/constants/index.js
import argonTheme from './Theme';
export {
  // articles,
  // Images, 
  argonTheme,
};

这里是定义对象的地方:

//userApplication/constants/Theme.js
export default {
  COLORS: {
    //LABEL: '#FE2472',
    INFO: '#11CDEF',
  }
};

如何使导入工作?

react-native ecmascript-6 ecmascript-7 ecmascript-2017
1个回答
0
投票

尝试:

//  userApplication/constants/index.js
import argonTheme from './Theme';
module.exports = {
  // articles,
  // Images, 
  argonTheme,
};

© www.soinside.com 2019 - 2024. All rights reserved.