【问题标题】:Why i can not do this on react native render and how i do?为什么我不能在反应原生渲染上做到这一点,我该怎么做?
【发布时间】:2021-03-24 17:19:47
【问题描述】:

我只是想要简单的东西,但我做不到......

import * as React from 'react';
import { 
  View, 
  Button,
  ScrollView 
} from 'react-native';

const server = require("../server.json");

export default class HomeScreen extends React.Component {

  constructor(props) {
    super(props);
    this.x = "oi";

  }
  render() {
    return (<ScrollView>
      <View><Text>Receitas:</Text></View>
      <View>{this.x}</View>
    </ScrollView>);
  }
}

出现这个错误

TypeError: Failed to constructor 'Text': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

【问题讨论】:

  • 导入文本..您忘记导入文本,这就是您出错的原因

标签: reactjs react-native render


【解决方案1】:

没有从 react-native 导入 Text

请补充

import { Text } from "react-native";

【讨论】:

    【解决方案2】:

    首先 this.x 是文本,在 react native 中你需要在元素中渲染文本。 其次,您应该使用 state 在 react native 上使用变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多