Skip to content

Commit

Permalink
Merge pull request #43 from RyKilleen/fix-form-state
Browse files Browse the repository at this point in the history
fix: use available hook for all of react-hook-form state
  • Loading branch information
RyKilleen authored Mar 12, 2022
2 parents 23001ae + 03d6773 commit 3e8183e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brancato",
"version": "0.3.1",
"version": "0.3.2",
"private": true,
"dependencies": {
"@algolia/autocomplete-js": "^1.5.3",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "brancato"
version = "0.3.1"
version = "0.3.2"
description = "A tool for stage-managing your life"
authors = ["Ryan Killeen"]
license = ""
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "brancato",
"version": "0.3.1"
"version": "0.3.2"
},
"build": {
"distDir": "../build",
Expand Down
21 changes: 7 additions & 14 deletions src/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ function Config() {
getValues,
setValue,
reset,
trigger,
formState,
} = useForm<Workflows>({
defaultValues,
});
const { isSubmitting } = formState;
const { isDirty } = useFormState({ control });
console.log({ isDirty, isSubmitting });
const { isDirty, isValid } = useFormState({ control });

useEffect(() => {
setTimeout(() => {
Expand All @@ -72,17 +70,10 @@ function Config() {
);

useEffect(() => {
async function validateAndSubmit() {
const valid = await trigger();

if (valid) {
handleSubmit(onSubmit)();
}
}
if (isDirty) {
validateAndSubmit();
if (isDirty && isValid) {
handleSubmit(onSubmit)();
}
}, [isDirty, handleSubmit, trigger, onSubmit]);
}, [isDirty, handleSubmit, isValid, onSubmit]);

//
useEffect(() => {
Expand Down Expand Up @@ -149,7 +140,9 @@ function Config() {
{/* <button type="button" onClick={addFilePath}>
Add file/program
</button> */}
<DevTool control={control} />
{(!process.env.NODE_ENV || process.env.NODE_ENV === "development") && (
<DevTool control={control} />
)}
</div>
);
}
Expand Down

0 comments on commit 3e8183e

Please sign in to comment.