【问题标题】:React Native take useState in class Error: Minified React error #321React Native 在类中使用 useState 错误:缩小的 React 错误 #321
【发布时间】:2021-05-28 08:18:47
【问题描述】:

我是新手反应原生和

我想创建一个简单的应用程序。

使用方法函数创建TextInput

并使 TextInput 集成到 Class export default class App extends React.Component

但不幸的是,我得到了 Error: Minified React 错误 #321,知道怎么弄吗? 非常感谢

完整代码:

import React, { useState } from 'react';
import { TextInput, Text, View, StyleSheet } from 'react-native';

function Example() {
  const [text, setText] = useState('')
   return (
    <View>
      <TextInput
        value={text}
        style={{ fontSize: 42, color: 'steelblue' }}
        placeholder="Type here..."
        onChangeText={(text) => {
          setText(text)
        }}
      />
      <Text style={{ fontSize: 24 }}>
        {'\n'}You entered: {text}
      </Text>
    </View>
  )
}

export default class App extends React.Component{
  render(){
  return (
    <View>
       {Example()}
    </View>
  );
  }
}

【问题讨论】:

    标签: react-native function class


    【解决方案1】:

    你需要像这样调用 React 组件:&lt;Example /&gt;

    这是您在codesandbox中的代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-24
      • 2021-03-14
      • 2020-05-11
      • 2022-11-03
      • 2021-09-30
      • 2020-09-13
      • 1970-01-01
      • 2021-10-16
      相关资源
      最近更新 更多