反应原生的导出方法/功能

时间:2018-06-18 05:01:55

标签: javascript reactjs react-native

export { width as responsiveHeight } from "react-native-responsive-dimensions";

我想导出名为responsiveHeight的{​​{1}}。这样做的正确方法是什么?因为这不起作用。

3 个答案:

答案 0 :(得分:3)

您的语法相反。您希望responsiveHeightwidth

试试这个

export { responsiveHeight as width } from "react-native-responsive-dimensions";

答案 1 :(得分:2)

你实际上正好相反,你正在使用你的宽度函数并添加一个名为responsiveHeight的别名,所以你需要这样做:

export { responsiveHeight } from "react-native-responsive-dimensions";

就像那样简单,以这种方式导出宽度,它应该没有问题。

答案 2 :(得分:0)

试试这个。

import React from "react";
import {responsive} from "react-native-responsive-ui";

@responsive
export default class Debug extends React.Component {
    render() {
        const {width, height} = this.props.window;
        console.log(`New window dimensions: ${width}x${height}`);
        return null;
    }
}