D
D
Davidaa_WoW2021-09-19 17:04:56
React
Davidaa_WoW, 2021-09-19 17:04:56

Why does Minified React error #321 occur?

I'm trying to get familiar with the useState hook, but I keep getting an error.
Below is the code. What am I doing wrong?

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

class BetterInput extends Component {
  
  render() {
    const { placeholder, type, restrictions, inputText } = this.props
    const [key, setKey] = useState(0);
    return (
      <View style={styles.wrapper}>
        <TextInput
        style={styles.input}
        placeholder={placeholder}
        onChangeText={()=>setKey(key+1)}
        ></TextInput>
        <Text
        >{key}</Text>
      </View>
    )
  }
}

const styles = StyleSheet.create({
  wrapper: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
  input: {
    borderColor: 'gray',
    borderWidth: 1,
    height: 45,
    width: 345,
    borderRadius: 10,
  }
})

export default BetterInput

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Simkav, 2021-09-19
@Davidaa_WoW

I suspect that this is due to the fact that you are using hooks in
doc classes

You can't use Hooks inside a class component, but you can definitely mix classes and function components with Hooks in a single tree.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question