Skip to content
Advertisement

How to disable an option based on a specific value in an array?

When the stock value in the Product array is less than 0 or 1, I want to disable that value in the options so that it cannot be selected.(disable =true) And if product stock is greater than 0, I want to be able to select that value.(disable =false) What should I do?

JavaScript

}

export default ProductPage

Advertisement

Answer

Use the disabled JSX property, which maps to the disabled attribute: disabled={item.stock < 1}

In context:

JavaScript

More minimal example:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement