Skip to content

Tag: javascript

Why I got Illegal arguments error with simple hash function?

This is my code I run I expected hashed password. Why does terminal point to illegal arguments? Answer In an object literal, password : bcrypt.hash(this.password, salt) calls bcrypt.hash and assigns its return value to the password property. In the code you’ve shown, this doesn’t refer to the obje…

Preview an many image before it is uploaded

For the first input it works well, but not for the second. Instead of updating the second one it updates the first. How do I separate this two input previews with the same function? Answer Firstly, the IDs should be unieque, so set “load” to “load1” and “load2” for the img …

Retain Values in two related Dropdown List after Page refresh

I have two dropdown lists where on changing the value in the first dropdown, the second dropdown is appended with the values based on the value selected in the first dropdown. My code is: Could anyone please suggest me how to retain the selected values in both dropdowns after page refresh? Answer Use localSto…

When do I must use the spread operator in useReducer?

I’ve noticed that in many useReducer examples, the spread operator is used in the reducer like this: However in many of my practices, I removed …state and had no issues at all. I understand that …state is used to preserve the state of the remaining states, but would a reducer preserve those …