Skip to content

Commit

Permalink
split location onChange to separate function. added temperature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomcv committed Jul 19, 2020
1 parent 7e62dc0 commit e4b1f92
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/MainContent/MainContent.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import React, { FunctionComponent, useState } from 'react';
import React, { FunctionComponent, useState, ChangeEventHandler } from 'react';
import LocationSelector from '../LocationSelector';
import TemperatureToggle from '../TemperatureToggle';
import { TemperatureUnit, Location } from '../../sharedTypes';
import './MainContent.css';

const MainContent: FunctionComponent = () => {
const [location, setLocation] = useState<Location>('lisbon');
const [temperatureUnit, setTemperatureUnit] = useState<TemperatureUnit>('celsius');

const handleLocationChange: ChangeEventHandler<HTMLSelectElement> = (event) => {
const value = event.target.value as Location;
setLocation(value);
};

return (
<main className="main-content">
<LocationSelector
value={location}
onChange={(event) => {
const value = event.target.value as Location;
setLocation(value);
}}
/>
<section className="controls-section">
<LocationSelector
value={location}
onChange={handleLocationChange}
/>
<TemperatureToggle
value={temperatureUnit}
onToggle={setTemperatureUnit}
/>
</section>
</main>
);
};
Expand Down

0 comments on commit e4b1f92

Please sign in to comment.