I want my toggle button to switch all my Celsius temperatures to Fahrenheit, but I don't know how to do this in this particular app. The Celsius temperature is defined in the state with an axios call:
class App extends Component {
state = {
temperature: undefined,
And then I have my Weather component:
const Weather = props => {
let tempC = props.temperature;
let tempF = (props.temperature * 9) / 5 + 32;
return (
<div className={Styles.outputs}>
{props.id && props.country && (
<div className={Styles.fontIcon}>
<i className={`owf owf-${props.id}`} />
</div>
)}
{props.city && props.country && (
<h2 className={Styles.outputCity}>
{props.city}, {props.country}
</h2>
)}
{props.main && props.description && (
<div className={Styles.outputDesc}>
{props.main}/{props.description}
</div>
)}
{props.id && props.country && <Toggle />}
<div className={Styles.outputDatas}>
<div className={Styles.outputData}>
{props.temperature && (
<div className={Styles.outputTitle}>
Temperature
<p className={Styles.outputResult}>{props.temperature}°C</p>{" "}
</div>
)}
</div>
<div className={Styles.outputData}>
{props.wind && (
<div className={Styles.outputTitle}>
Wind
<p className={Styles.outputResult}>{props.wind} m/s</p>
</div>
)}
</div>
<div className={Styles.outputData}>
{props.humidity && (
<div className={Styles.outputTitle}>
Humidity
<p className={Styles.outputResult}>{props.humidity}%</p>
</div>
)}
</div>
</div>
</div>
);
};
I have tried to make two different axios calls for the different temperatures and I was trying to play with the buttons and the props but I can't make it work.
I want to use my Toggle switch to change from Fahrenheit to Celsius.
const Toggle = () => {
return (
<label className={Styles.switchWrap}>
<input type="checkbox" />
<div className={Styles.switch} />
</label>
);
};