added app context with reducer

This commit is contained in:
Thomas Ruoff
2020-07-01 00:25:36 +02:00
parent 96c62e3e9f
commit 563d57a8ba
6 changed files with 207 additions and 124 deletions

View File

@@ -1,23 +1,31 @@
export default function RangeSelect({ multipleDays, setMultipleDays }) {
return (
<div>
Ich will das Bussle für
<input
type="radio"
id="single"
name="days"
value="singleDay"
onChange={() => setMultipleDays(false)}
/>
<label htmlFor="single">einen Tag</label>
<input
type="radio"
id="multiple"
name="days"
value="multipleDays"
onChange={() => setMultipleDays(true)}
/>
<label htmlFor="multiple">mehrere Tage</label> mieten
</div>
)
import { useContext } from 'react'
import { AppContext, ACTIONS } from '../context/appStore'
export default function RangeSelect() {
const { state, dispatch } = useContext(AppContext)
return (
<div>
Ich will das Bussle für
<input
type="radio"
id="single"
name="days"
checked={state.multipleDays === false}
onChange={() =>
dispatch({ type: ACTIONS.SET_MULTIPLE_DAYS, payload: false })
}
/>
<label htmlFor="single">einen Tag</label>
<input
type="radio"
id="multiple"
name="days"
checked={state.multipleDays === true}
onChange={() =>
dispatch({ type: ACTIONS.SET_MULTIPLE_DAYS, payload: true })
}
/>
<label htmlFor="multiple">mehrere Tage</label> mieten
</div>
)
}