Компоненты импорта / экспорта - PullRequest
0 голосов
/ 12 июля 2020

Я пытаюсь создать пользовательский компонент ввода и отобразить его на другой странице Вот мой код

import React from "react";
import { View, TextInput, StyleSheet, Text } from "react-native";
import {
  widthPercentageToDP as wp,
  heightPercentageToDP as hp,
} from "react-native-responsive-screen";
import { MaterialCommunityIcons } from "@expo/vector-icons";
class RegisterTextBox extends React.Component {
  render() {
    const RegisterTextInput = ({
      value,
      placeholder,
      onChangeText,
      onBlur,
      secureTextEntry,
      inputStyle,
      viewStyle,
      eyeIcon = false,
    }) => {
      return (
        <View style={[styles.container, viewStyle]}>
          <TextInput
            style={[styles.main, inputStyle]}
            value={value}
            onChangeText={onChangeText}
            onBlur={onBlur}
            placeholder={placeholder}
            secureTextEntry={secureTextEntry}
          />
          {eyeIcon ? (
            <MaterialCommunityIcons
              name="eye-off"
              size={24}
              color="black"
              style={{ paddingTop: 5 }}
            />
          ) : (
            <View />
          )}
        </View>
      );
    };

    const styles = StyleSheet.create({
      container: {
        height: hp(5.4),
        width: wp(65.2),
        borderBottomColor: "grey",
        borderBottomWidth: 1,
        flexDirection: "row",
        justifyContent: "space-between",
      },
      main: {},
    });
  }
}
export default RegisterTextBox;

Я хочу, чтобы const RegisterTextInput отображался и использовал данные Dynami c, но Кажется, я получаю сообщение об ошибке при попытке его использования "Ошибка: RegisterTextBox (...): ничего не было возвращено от рендеринга. Вот как я пытаюсь его использовать:

...
import RegisterTextInput from "../components/registerInput";
<View style={styles.emailInputsContainer}>
            <RegisterTextInput
              style={styles.emailInput}
              placeholder="Email"
              value={"email"}
              onChangeText={}
            />
          </View>
...


Где мой Проблема? Примечание: я хочу использовать состояния этого компонента

1 Ответ

1 голос
/ 12 июля 2020

Попробуйте с этим ...

import React from "react";
import { View, TextInput, StyleSheet, Text } from "react-native";
import {
  widthPercentageToDP as wp,
  heightPercentageToDP as hp,
} from "react-native-responsive-screen";
import { MaterialCommunityIcons } from "@expo/vector-icons";

class RegisterTextBox extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    const {
      value,
      placeholder,
      onChangeText,
      onBlur,
      secureTextEntry,
      inputStyle,
      viewStyle,
      eyeIcon = false,
    } = this.props;
    return (
      <View style={[styles.container, viewStyle]}>
        <TextInput
          style={[styles.main, inputStyle]}
          value={value}
          onChangeText={onChangeText}
          onBlur={onBlur}
          placeholder={placeholder}
          secureTextEntry={secureTextEntry}
        />
        {eyeIcon ? (
          <MaterialCommunityIcons
            name="eye-off"
            size={24}
            color="black"
            style={{ paddingTop: 5 }}
          />
        ) : (
          <View />
        )}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    height: hp(5.4),
    width: wp(65.2),
    borderBottomColor: "grey",
    borderBottomWidth: 1,
    flexDirection: "row",
    justifyContent: "space-between",
  },
  main: {},
});

export default RegisterTextBox;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...