V
V
VolodymyrWork2021-06-14 14:47:28
React
VolodymyrWork, 2021-06-14 14:47:28

How to fix the problem that when passing props the number 0 is considered as null?

I have an Input which takes a value from an object. The value is a number. And if there is a value, I pass it; if not, then I must pass null in order to be able to erase all values ​​from the input. If I enter some values ​​in the input, I immediately change it in the object through setState. But now when I pass the number 0, it is not displayed, an empty input is displayed. That is, why is it if the value 0 lx of the component is passed not the number 0 but the value null. How can I fix this?

<Input
value={user.laps || null}
onChange={(value) => {
  setSession({
    ...user,
    laps: Number(value),
  });
}}
/>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WbICHA, 2021-06-14
@WblCHA

https://developer.mozilla.org/en/docs/Web/JavaScript...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question