Currently, I have a button that is toggling a ternary expression and it's working, but I can't imagine that creating a separate ternary expression for each line where I want to display data is the best practice.
Is there a better way to change between kilometers and miles across an entire page? My redux store contains both versions of the same distance and this is what I have so far:
const YourDistance = ({distanceInKms, distanceInMiles}) => {
const [isToggled, setToggled] = useState(false)
return (
<div>
{ isToggled ? <h2>{distanceInKms}</h2> : <h2>{distanceInMiles}</h2> }
<button onClick={() => setToggled(!isToggled)}>Convert</button>
</div>
)};
If anyone has any ideas I would really appreciate it.