I have a react application with redux. In the app there is a text field and a button. When the button is clicked an action creator is dispatched.
Here is an example of the component
import {useState} from "react";
import {useDispatch, useSelector} from "react-redux";
import updateEmail from "redux/actions/updateEmail";
const MyForm = () => {
const [email, setEmail] = useState("")
const dispatch = useDispatch()
const {saving, error} = useSelector(state => state.saveEmail)
if (saving) return <div>Please wait.....</div>
if (error) return <div>Something has gone wrong.....</div>
return (
<div className="container">
<p>Forgot Password</p>
<input
value={email}
onChange={e => setEmail(e.target.value)}
className="input is-large"
type="text"
placeholder="Email"
></input>
<a onClick={() => dispatch(updateEmail())} className="has-text-weight-bold">Login</a>
</div>
);
};
export default MyForm;
when the redux state saving, error
changes, the UI re-renders. The state defines what the user is displayed.
In a NextJS application, how would I go about doing this without using redux. What is the correct way without redux
- for the client to make rest calls similar to above
- the UI to re-render based on the state similar to above example