Skip to content
Advertisement

Function doesn’t accept updated value React JS

ascendingDirectionSort has ‘true’ initial value. It can be changed by dropdownlist. When it is changed, console.log in the sortData function shows updated value, but only the ascendingDirectionSort==true condition executes, even when it’s false.

JavaScript

Advertisement

Answer

JavaScript

While you are passing boolean values to the value props, they will be rendered as HTML attributes and so will be converted to strings.

JavaScript

You are testing the truthiness of the value of that variable.

true, "true" and "false" are all true values.


Use strings consistently.

JavaScript

and

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