hook input on LatlOutput to dispatch function

This commit is contained in:
Sorrel Bri 2020-03-02 19:14:51 -08:00
parent 49419a39ee
commit 4ee5bc0f78

View file

@ -2,6 +2,34 @@ import React from 'react';
import './LatlOutput.scss'; import './LatlOutput.scss';
const LatlOutput = ({results, options, dispatch}) => { const LatlOutput = ({results, options, dispatch}) => {
const handleClick = e => dispatchFunc => {
e.preventDefault()
return dispatchFunc();
}
const dispatchClear = () => {
const clearAction = {
type: 'CLEAR',
value: {}
}
dispatch(clearAction)
}
const dispatchParse = () => {
const parseAction = {
type: 'PARSE_LATL',
value: {}
}
dispatch(parseAction)
}
const dispatchRun = () => {
const runAction = {
type: 'RUN',
value: {}
}
dispatch(runAction)
}
return ( return (
<div className="LatlOutput"> <div className="LatlOutput">
@ -10,7 +38,7 @@ const LatlOutput = ({results, options, dispatch}) => {
<input <input
className="form form--remove" className="form form--remove"
type="submit" type="submit"
onClick={e=>{e.preventDefault()}} onClick={e=>handleClick(e)(dispatchClear)}
value="Clear" value="Clear"
/> />
@ -19,7 +47,7 @@ const LatlOutput = ({results, options, dispatch}) => {
name="Parse" name="Parse"
className="form form--add" className="form form--add"
type="submit" type="submit"
onClick={e=>{e.preventDefault()}} onClick={e=>handleClick(e)(dispatchParse)}
value="Parse" value="Parse"
/> />
@ -28,7 +56,7 @@ const LatlOutput = ({results, options, dispatch}) => {
name="Run" name="Run"
className="form form--add" className="form form--add"
type="submit" type="submit"
onClick={e=>{e.preventDefault()}} onClick={e=>handleClick(e)(dispatchRun)}
value="Run" value="Run"
/> />
</form> </form>