Skip to content

Conversation

@CarrotBRRR
Copy link

Please have mercy

Comment on lines +37 to +39
const [battery, setBattery] = useState(NaN);
const [speed, setSpeed] = useState(NaN);
const [weather, setWeather] = useState(50);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use explicit type definitions

const [speed, setSpeed] = useState(NaN);
const [weather, setWeather] = useState(50);

const [range, setRange] = useState(NaN);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create a separate state variable for range here? Can't we just calculate range from battery speed and weather state variables? Remember, when you update any state variable, it will cause your component (App.tsx) to re-render(unless you use useMemo/useCallback hooks, will get to this in a future lesson hopefully), and update all variables.

<SpeedInput />
<BatteryInput />
<SpeedInput speed={speed} setSpeed={setSpeed} />
{isNaN(speed) && <p className="text-red-500">Speed is Required</p>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the app first loads, this message shouldn't be showing

)}
<BatteryInput battery={battery} setBattery={setBattery} />
{isNaN(battery) && (
<p className="text-red-500">Battery is Required</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the app first loads, this message shouldn't be showing

@@ -1,4 +1,9 @@
const BatteryInput = () => {
interface props {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please capitalize props

@@ -1,4 +1,9 @@
const SpeedInput = () => {
interface props {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please capitalize props

@@ -1,6 +1,11 @@
const WeatherInput = () => {
interface props {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please capitalize props

type="range"
min="0"
max="100"
value="50"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be using controlled inputs here, let's say we have add some function in App.tsx that runs setWeather(12), would the slider be updated to reflect the change?

Calculate!
</button>
{!isNaN(range) && (
<p text-white>The predicted range of the Eylsia is {range} km</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix your output to 3 decimal places

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants