If you are just looking to use useReducer to clear your form you can use dispatch to do so. Let's use this example button component as an example.
//Component
<Button onClick={() => {dispatch({ type: "CLEAR_FORM"})}}>Submit</Button>
After clicking the button "CLEAR_FORM" is dispatched to the reducer.
//Form Initial State & Reducer switch statement
export const initialState={
username:"",
password:""
}
export const reducer = (state, action) => {
switch(action.type){
case: "CLEAR_FORM":
return {
username:"",
password:"",
}
default:
return state
}
}
When the reducer gets the { type: "LOG_OUT" }, in this case, it resets the username and password fields to an empty string.
https://reactjs.org/docs/hooks-reference.html#usereducer