This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(useForm): conditional form not working
- Loading branch information
Showing
11 changed files
with
208 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"react-cool-form": patch | ||
--- | ||
|
||
Fix(useForm): conditional form not working |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
import { useState } from "react"; | ||
import { useForm } from "react-cool-form"; | ||
|
||
export default () => { | ||
const Form = () => { | ||
const [show, setShow] = useState(true); | ||
const { form } = useForm({ | ||
defaultValues: { test: "test" }, | ||
onSubmit: (values, { formState }) => | ||
console.log("onSubmit: ", formState.values), | ||
}); | ||
|
||
return ( | ||
<form ref={form}> | ||
<input name="test" /> | ||
<input type="submit" /> | ||
</form> | ||
<> | ||
<button type="button" onClick={() => setShow(!show)}> | ||
Internal Toggle | ||
</button> | ||
{show && ( | ||
<form ref={form}> | ||
<input name="test" /> | ||
<input type="submit" /> | ||
</form> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default () => { | ||
const [show, setShow] = useState(true); | ||
|
||
return ( | ||
<> | ||
<button type="button" onClick={() => setShow(!show)}> | ||
External Toggle | ||
</button> | ||
{show && <Form />} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export { default as useState } from "./useState"; | ||
export { default as useLatest } from "./useLatest"; | ||
export { default as useIsoLayoutEffect } from "./useIsoLayoutEffect"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.