null input in props

tags: learning programming react

content

sometimes i see errors like this:

Warning: `value` prop on `input` should not be null. Consider using an empty string to clear the component or `undefined` for uncontrolled components.
  • it indicates some input is null
  • in this case, i have:
<TextField
    label="Coffee (g)"
    value={recipeData.coffeeWeight}
    disabled={readonly}
/>
  • and recipeData.coffeeWeight might be null or undefined
  • we just need to give it a default value
<TextField
    label="Coffee (g)"
    value={recipeData.coffeeWeight || ''}
    disabled={readonly}
/>

up

down

reference