I have a 'login' button on the login page and I want to add another 'register' button on the same login page, at first it worked, I was able to put the login button but I can't find ways to put the registration button.
I've already put the two together inside the same render() but it didn't work, it's like 2 'submit' buttons and that's not what I want.
I tried to do it another way as it is in the code below, it does not show any error, but the button is not rendered on the page, it does not appear. Can anyone help me with this?
function Form({ template, onSubmit }: any) {
const { title, fields } = template;
const [buttonFields, setButtonFields] = useState([])
const renderFields = (fields: any) => {
return fields.map((field: any) => {
const { title, type } = field;
switch (type) {
case 'buttonLogin':
return (
<Button
key={title.id}
style={{}}
>
Enter
</Button>
)
}
})
}
const renderFieldsButton = (buttonFields: any) => {
return buttonFields.map((buttonField: any) => {
const { type, titleRegisterButton } = buttonField;
switch (type) {
case 'buttonRegister':
return (
<Button
key={titleRegisterButton.id}
style={{}}
>
Register
</Button>
)
}
})
}
return (
<>
<div>
<form onSubmit={handleSubmit(onSubmit)}>
{renderFields(fields)}
</form>
{renderFieldsButton(buttonFields)}
</div>
</>
)
}
export default Form
function LoginForm(props: any) {
const template = {
title: '',
fields: [
{
title: 'Login Button',
type: 'buttonLogin',
},
]
}
const registerButton = {
titleRegisterButton: 'Register',
buttonFields: [
{
titleRegisterButton: 'Register Button',
type: 'buttonRegister'
}
]
}
return (
<div >
<Form
template={template}
registerButton={registerButton}
onSubmit={onSubmit}
/>
</div>
)
}
function onSubmit(values: any) {
console.log(values)
}
export default LoginForm
switches? They look to be making things incredibly more verbose for no reason. You could also consider to type your functions properly - usinganydefeats the purpose of TypeScript and can easily lead to more runtime errorsany