javascript - How to make a form in React Native? - Stack Overflow

I want to make a form in react native using Form Hooks. It doesn't work for me.I have installed ho

I want to make a form in react native using Form Hooks. It doesn't work for me.

I have installed hook form with this mand :

npm install react-hook-form

And here is my code :

import React from "react";
import { useForm } from "react-hook-form";

const InscriptionScreen = () => {
  return (
    <form>
      <input type="text" placeholder="Email" name="email"/>
      <input type="password" placeholder="Password" name="password"/>
      <input type="submit"/>
    </form>
  );
};

export default InscriptionScreen

I get this error :

View config not found for name input. Make sure to start ponent names with a capital letter.

Do I need to do more configurations or is there a missing keyword in my code?

I want to make a form in react native using Form Hooks. It doesn't work for me.

I have installed hook form with this mand :

npm install react-hook-form

And here is my code :

import React from "react";
import { useForm } from "react-hook-form";

const InscriptionScreen = () => {
  return (
    <form>
      <input type="text" placeholder="Email" name="email"/>
      <input type="password" placeholder="Password" name="password"/>
      <input type="submit"/>
    </form>
  );
};

export default InscriptionScreen

I get this error :

View config not found for name input. Make sure to start ponent names with a capital letter.

Do I need to do more configurations or is there a missing keyword in my code?

Share Improve this question edited Apr 26, 2020 at 20:25 AmerllicA 32.7k17 gold badges144 silver badges167 bronze badges asked Apr 26, 2020 at 20:03 SegfaultSegfault 331 silver badge7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You use HTML elements in React-Native, you should use the React-Native elements and also use useForm, like below:

import React, { useEffect, useCallback } from 'react';
import { View, TextInput, Button } from 'react-native';
import { useForm } from 'react-hook-form';

const InscriptionScreen = () => {
  const { register, handleSubmit, setValue } = useForm();
  const onSubmit = useCallback(formData => {
    console.log(formData);
  }, []);
  const onChangeField = useCallback(
    name => text => {
      setValue(name, text);
    },
    []
  );

  useEffect(() => {
    register('email');
    register('password');
  }, [register]);

  return (
    <View>
      <TextInput
        autoCompleteType="email"
        keyboardType="email-address"
        textContentType="emailAddress"
        placeholder="Email"
        onChangeText={onChangeField('email')}
      />
      <TextInput
        secureTextEntry
        autoCompleteType="password"
        placeholder="Password"
        onChangeText={onChangeField('password')}
      />
      <Button title="Submit" onPress={handleSubmit(onSubmit)} />
    </View>
  );
};

export default InscriptionScreen;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745584221a4634431.html

相关推荐

  • javascript - How to make a form in React Native? - Stack Overflow

    I want to make a form in react native using Form Hooks. It doesn't work for me.I have installed ho

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信