Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

Commit 196e00f

Browse files
committed
improve props name
1 parent 6388fba commit 196e00f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function App() {
3737
<form onSubmit={handleSubmit(e => console.log(e))}>
3838
<input name="test" ref={register} />
3939
<HookFormInput
40-
children={Select}
40+
input={Select}
41+
rules={{ required: true }}
4142
options={options}
4243
name="ReactSelect"
4344
{...methods}

src/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import * as React from 'react';
22

33
type Props = {
44
setValue: (name: string, value: any) => void;
5-
register: (ref: any) => void;
5+
register: (ref: any, rules: any) => void;
66
name: string;
7-
children: any;
7+
input: any;
8+
rules: any;
89
};
910

1011
const HookFormInput = (props: Props) => {
@@ -33,10 +34,11 @@ const HookFormInput = (props: Props) => {
3334
},
3435
},
3536
),
37+
{ ...props.rules },
3638
);
3739
}, [props, value]);
3840

39-
return React.createElement(props.children, {
41+
return React.createElement(props.input, {
4042
...props,
4143
onChange: handleChange,
4244
value,

0 commit comments

Comments
 (0)