From 7cc9654507ae10731d54342009b630b11dbb1db3 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Thu, 26 Sep 2019 21:30:14 +0200 Subject: [PATCH] testing --- test/test.tsx | 101 ++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/test/test.tsx b/test/test.tsx index 71b5500..b17f740 100644 --- a/test/test.tsx +++ b/test/test.tsx @@ -1,65 +1,70 @@ -import React, { useState } from 'react' +import React from 'react' import ReactDOM from 'react-dom' -import { useForm, HTMLInputExtractor } from '../' +import { useForm } from '../' const TextError: React.FC<{ error?: string }> = ({ error }) => !error - ? null - :
{error}
+ ? null + :
{error}
const Index: React.FC = () => { - const { auto, form, update, errors } = useForm({ - username: '', - password: '', - type: 'formhero', - awesome: true, - }, { - username: /^test/, - password: { - validator: /^.{3,}$/, - message: 'To short', - }, - awesome: (value) => !!value - }, { extractor: HTMLInputExtractor }) + const { auto, form, errors } = useForm({ + username: '', + password: '', + type: 'formhero', + awesome: true, + }, { + username: /^test/, + password: { + validator: /^.{3,}$/, + message: 'To short', + }, + awesome: (value) => !!value + }) - const _submit = (e: React.MouseEvent) => { - e.preventDefault() - console.log(form, errors) - } + const _submit = (e: React.FormEvent) => { + e.preventDefault() + console.log(form, errors) + } - return ( -
-
-
Username
- - -
+ return ( +
+ +
Username
+ + {errors.username && 'Something went wrong'} + +
-
Password
- - -
+
Password
+ + +
-
Which one to choose?
- -
+
Which one to choose?
+ +
-
Is it awesome?
- e.target.checked })} /> - -
+
Is it awesome?
+ e.target.checked + })} /> + +
- - -
- ) + + +
+ ) } ReactDOM.render(, document.getElementById('root'))