I am using Redux Toolkit (RTK) and Redux Toolkit Query (RTK-Query).
Is it best practice, necessary, or advised in any scenario to still use thunks
, or should I move all logic into components? (like in handleLogin()
below)
const Login = () => {
const dispatch = useDispatch()
const [formState, setFormState] = useState({ name: '', password: '' })
const [login, { isLoading }] = useLoginMutation()
const { push } = useHistory()
const handleLogin = async () => {
try {
const user = await login(formState).unwrap()
dispatch(setCredentials(user));
} catch (e) {
console.error(e)
}
}
return (
<div>
<input type="text" name="name" placeholder="name" />
<input type="password" name="password" placeholder="password" />
<button onClick={handleLogin}>Login {isLoading ? '...' : ''}</button>
</div>
)
}
export default Login