Created
August 18, 2019 13:52
-
-
Save msarsha/23e27f135922e9e9dab4978b1dea2aa3 to your computer and use it in GitHub Desktop.
react component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const userFormReducer = (state, action) => { | |
switch (action.type) { | |
case actionTypes.INPUT_CHANGE: { | |
return { | |
...state, | |
[action.name]: action.value | |
} | |
} | |
default: | |
return state; | |
} | |
}; | |
const NewEditUserModal = (props) => { | |
const [state, dispatch] = useReducer(userFormReducer, props.user || {}); | |
const handleInputChange = (name, value) => { | |
dispatch({type: actionTypes.INPUT_CHANGE, value, name}) | |
}; | |
return ( | |
<React.Fragment> | |
<form> | |
<span>User Modal</span> | |
<label> | |
Full Name: | |
<input type="text" value={state.fullName} onChange={(e) => { | |
handleInputChange('fullName', e.target.value) | |
}}/> | |
</label> | |
<Button onClick={props.closeModal} type="button">Close</Button> | |
</form> | |
{state.fullName} | |
</React.Fragment> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment