Skip to content

Tag: ecmascript-6

Unable to display Date in JSX in ReactJS

Following is my code which is working fine if I initialize test with a string, though if I changed it to new Date() its throwing error. Let me know what I am doing wrong as I just started with React. Code – Error – Objects are not valid as a React child (found: Fri Jul 21 2017 02:11:18 GMT+0530 (I…

How to properly use Object.setPrototypeOf()

So I’ve been getting up to speed on some of the newer features of JavaScript and have been reading about Object.setPrototypeOf(). I ran across this bit of code from MDN which deals with inheriting from regular objects. But I’m confused at how they use Object.setPrototypeOf() here. I expected them …

Programmatically cause onBlur to trigger in react

I use onBlur to close a dropdown, but I also want to handle a click handler of an li which is render within, setState won’t work here, the behavior is broken when user try to open the dropdown again, try it here: http://jsfiddle.net/ur1rbcrz My code: Answer Your code is not working because, even though …

Enums in Javascript with ES6

I’m rebuilding an old Java project in Javascript, and realized that there’s no good way to do enums in JS. The best I can come up with is: The const keeps Colors from being reassigned, and freezing it prevents mutating the keys and values. I’m using Symbols so that Colors.RED is not equal to…