-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial commit for Allow Asynchronous Models * allow async models * allow more modern versions of react * rework dependencies * add strict equality
- Loading branch information
1 parent
1c2a4f6
commit d57a95f
Showing
9 changed files
with
326 additions
and
78 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useForm } from '../src'; | ||
import { Input } from './components/Input'; | ||
|
||
function useMyApiValue(): string { | ||
const [value, setValue] = React.useState(''); | ||
useEffect(() => { | ||
setTimeout(() => setValue('John'), 1000); | ||
}, []); | ||
return value; | ||
} | ||
|
||
export function SimpleDelayedFields(): JSX.Element { | ||
const name = useMyApiValue(); | ||
const { | ||
model, | ||
changes, | ||
fields, | ||
onSubmit, | ||
valid, | ||
dirty, | ||
submissionStatus, | ||
reset, | ||
} = useForm({ | ||
model: { name }, | ||
onSubmit: async ({ model }) => { | ||
// eslint-disable-next-line no-console | ||
console.log(model); | ||
}, | ||
validations: { | ||
name: 'required', | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<h2 id="simple-delayed-fields">Simple Delayed Fields</h2> | ||
<form onSubmit={onSubmit}> | ||
<div className="stack"> | ||
<Input label="Name: " {...fields.name} /> | ||
<footer> | ||
<button>Submit</button> | ||
<button onClick={reset} type="button"> | ||
Reset | ||
</button> | ||
</footer> | ||
</div> | ||
</form> | ||
<h4>Model</h4> | ||
<pre> | ||
{JSON.stringify({ model, valid, dirty, submissionStatus }, null, 2)} | ||
</pre> | ||
<h4>Changes</h4> | ||
<pre>{JSON.stringify({ changes }, null, 2)}</pre> | ||
<a href="#">Back</a> | ||
</> | ||
); | ||
} |
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
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.