简体   繁体   English

在React Native中导出方法/功能

[英]Export method/function in react native

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

I want to export responsiveHeight with name width . 我想导出名称为width responsiveHeight width What is correct way to do this? 正确的方法是什么? As this is not working. 由于这是行不通的。

Your syntax is opposite. 您的语法相反。 You want to get responsiveHeight as width . 您想获得width responsiveHeight width

Try this 尝试这个

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

You're actually doing the opposite, you are taking your width function and add it an alias called responsiveHeight, so you need to do this: 实际上,您在做相反的事情,您正在使用width函数,并为其添加了一个名为sensitiveHeight的别名,因此您需要执行以下操作:

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

just as simple as that, export width in that way, it should work with no issue. 就这么简单,以这种方式导出宽度,它应该没有问题。

Try This One. 试试这个。

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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM