javascript:

Conditional Render in React

In react, sometimes we need to render a component based on some flag, for example, we need to display a different set of information to the admin users than the normal users. We have a prop called isAdmin render () { const { isAdmin } = this.props return ( <div> { isAdmin ? <CustomeComponent {...propSetA} / > : <CustomeComponent {...propSetB} / > } </div> ) } Looks good right, but there is one problem.

by lek tin in "javascript" access_time 1-min read

When You New a Class in JavaScript?

Here is an example of instantiating a class using the new operator: class Person { constructor(name, age) { this.name = name; this.age = age; } } const asian = new Person('Alice', 25); console.log(asian); As you can see from below, asian is not a class, it is instead, an object: [object Object] { age: 25, name: "Alice" } The values of asian are set by the constructor of the Person class.

by lek tin in "javascript" access_time 1-min read