chore(example): fix translation with global message
This commit is contained in:
parent
52081972e9
commit
c979bab553
@ -7,7 +7,7 @@ import { useFormTranslation } from '../hooks/useFormTranslation'
|
|||||||
import { userSchema } from '../models/User'
|
import { userSchema } from '../models/User'
|
||||||
import { FormState } from './design/FormState'
|
import { FormState } from './design/FormState'
|
||||||
|
|
||||||
const wait = async (ms: number): Promise<void> => {
|
const simulateServerRequest = async (ms: number): Promise<void> => {
|
||||||
return await new Promise((resolve) => {
|
return await new Promise((resolve) => {
|
||||||
setTimeout(resolve, ms)
|
setTimeout(resolve, ms)
|
||||||
})
|
})
|
||||||
@ -22,12 +22,12 @@ export const FormExample: React.FC = () => {
|
|||||||
formData,
|
formData,
|
||||||
formElement
|
formElement
|
||||||
) => {
|
) => {
|
||||||
await wait(4000)
|
await simulateServerRequest(4000)
|
||||||
console.log('onSubmit:', formData)
|
console.log('onSubmit:', formData)
|
||||||
formElement.reset()
|
formElement.reset()
|
||||||
return {
|
return {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('common:success')
|
value: 'common:success-message'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,12 @@ export const FormExample: React.FC = () => {
|
|||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
</Form>
|
</Form>
|
||||||
<FormState id='message' state={fetchState} message={message} />
|
|
||||||
|
<FormState
|
||||||
|
id='message'
|
||||||
|
state={fetchState}
|
||||||
|
message={message != null ? t(message) : undefined}
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"about": "This is an example of using <0>`react-component-form`</0> inside a Next.js application. The application shows how to use the <0>`{`<Form />`}`</0> component with the <0>`useForm`</0> hook to validate and submit a form with a <0>`name`</0> and an <0>`email`</0> input.",
|
"about": "This is an example of using <0>`react-component-form`</0> inside a Next.js application. The application shows how to use the <0>`<Form />`</0> component with the <0>`useForm`</0> hook to validate and submit a form with a <0>`name`</0> and an <0>`email`</0> input.",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"error": "Error",
|
"error": "Error",
|
||||||
"success": "Success",
|
"success": "Success",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"about": "Ceci est un exemple d'utilisation de <0>`react-component-form`</0> dans une application Next.js. L'application montre comment utiliser le composant <0>`{`<Form />`}`</0> avec le hook <0>`useForm`</0> hook pour valider et soumettre un formulaire avec un input `name` et `email`.",
|
"about": "Ceci est un exemple d'utilisation de <0>`react-component-form`</0> dans une application Next.js. L'application montre comment utiliser le composant <0>`<Form />`</0> avec le hook <0>`useForm`</0> hook pour valider et soumettre un formulaire avec un input `name` et `email`.",
|
||||||
"name": "Nom",
|
"name": "Nom",
|
||||||
"error": "Erreur",
|
"error": "Erreur",
|
||||||
"success": "Succès",
|
"success": "Succès",
|
||||||
|
Reference in New Issue
Block a user