I am pretty new to js so i have an confusion over when to use which type of call, any help or any link would be great
for example while submiting a form i was using onSubmit={() => onSubmit()} but it doesn't work while i changed that to onSubmit={onSubmit()} it works
const onSubmit = async (e) => {
e.preventDefault();
const credentials = {
emailAddress: email.trim(),
password: password,
rememberMe: rememberMe,
};
if (!emailError && email && password) {
setLoading(true);
login(credentials)
.then((result) => {
setLoading(false);
if (result) {
setError(false);
window.location.assign('/');
} else {
setError(t('Login.InvalidCredentials'));
}
})
.catch((err) => {
setError(t('Login.ServerError'));
setLoading(false);
});
}
};
<Form fontColor={(props) => props.theme.colors.grey.base} onSubmit={onSubmit}>
<Loader visibility={loading} />
<LoginDiv>
<Label>{t('E-mail')}</Label>
<Input
id={'email'}
type={'email'}
placeholder={'johndoe@email.com'}
value={email}
onChange={(e) => emailValidation(e.target.value)}
/>
<Status>{emailError}</Status>
</LoginDiv>
<PasswordDiv>
<Label>{t('Password')}</Label>
<Input
id={'password'}
placeholder={'●●●●●●●●●●●●●●'}
value={password}
onChange={(e) => handlePassword(e)}
onKeyPress={() => handleKeyPress()}
/>
<IconDiv>
<Eye onClick={() => setShow(!showPassword)} />
</IconDiv>
</PasswordDiv>
<Column>
<ForgetText
onClick={() => props.history.push('/forgot_password')}
>
{t('Login.Forgotten')}
</ForgetText>
<Remember>
<label>
<Input
type={'checkbox'}
onClick={() => setRemeber(!rememberMe)}
value={rememberMe}
/>
{t('Login.Remember')}
</label>
</Remember>
</Column>
<Button
type='submit'
>
{t('Sign In')}
</Button>
</Form>
so why it is working now and why not working when using it in this way (onSubmit={() => onSubmit()}), i don't know why and when to use which any help would be much appriciated, or any links where i get to know about this and usage thanks in advance :)