【问题标题】:How to import and use this File in my App.js view如何在我的 App.js 视图中导入和使用此文件
【发布时间】:2019-06-27 09:30:41
【问题描述】:

我想在我的 react native 项目的 Appjs 视图中导入它。
我尝试了很多方法,但它不起作用。我的意思是我想在我的视图中渲染它。如何在我的 Appjs 中导入并显示此文件。任何人都可以请帮助我,这对我来说非常重要。

这是我的代码:

import ForwardRef from '../../constants/UI_login/Home_Landing_Page/BackgroundComponent'
import React from "react";
import Svg, { Defs, LinearGradient, Stop, Rect } from "react-native-svg";
/* Adobe XD React Exporter has dropped some elements not supported by react-native-svg: style */

const BackgroundComponent = ({ svgRef }) => (
  <Svg width={375} height={247} viewBox="0 0 375 247" ref={svgRef}>
    <Defs>
      <LinearGradient
        id="a"
        x1={0.5}
        y1={0.807}
        x2={0.5}
        y2={1}
        gradientUnits="objectBoundingBox"
      >
        <Stop offset={0} stopColor="#fff" />
        <Stop offset={1} stopColor="#fff" stopOpacity={0} />
      </LinearGradient>
    </Defs>
    <Rect className="a" width={375} height={247} />
  </Svg>
);

const ForwardRef = React.forwardRef((props, ref) => (
  <BackgroundComponent svgRef={ref} {...props} />
));
export default ForwardRef;

App.js

import React from 'react';
import { StyleSheet} from 'react-native';
//import {Actions} from 'react-native-router-flux';
import Routes from './components/Routes';
import {firebaseConfig} from "./constants/ApiKeys";
import ForwardRef from '../../constants/UI_login/Home_Landing_Page/BottomNavigationComponent'

import {AppContainer} from './components/Navigation'

import * as firebase from 'firebase';

    if (!firebase.apps.length) { firebase.initializeApp(firebaseConfig); }

    console.ignoredYellowBox = ['Setting a timer'];
    export default class App extends React.Component {

        render() {
            return (
                <AppContainer/>
                <ForwardRef/>
            );
        }
    }

现在我得到一个黑色的空白空间

【问题讨论】:

  • 能否提供更多信息(错误日志等)?
  • @ biruk1230 现在我得到一个黑色的空白空间
  • 如何渲染 AppContainer 和 ForwardRef 因为它们是两个返回元素。添加代码
  • @Ashwin Mothilal 检查 app.js

标签: reactjs react-native svg import export


【解决方案1】:

您使用的是默认导出而不是命名导出,所以不是

import {ForwardRef} from "..."

你必须写

import ForwardRef from "..."

【讨论】:

  • k... 以及我如何应用到我的视图... 以查看其中的 svg。并感谢您的 relpay
【解决方案2】:

:)

请尝试执行以下操作:

  1. 打开AppContainer组件文件;
  2. 在文件头部添加import你的BackgroundComponent组件;
  3. 并将&lt;ForwardRef/&gt; 添加到render return 方法中:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 2017-12-20
    • 2020-12-07
    相关资源
    最近更新 更多