height={10}
This defaults to px, which is the decided-on sizing unit for most cases. Also, React Native requires only a number, so may as well stay consistent between stacks.
margin-top
When viewing and building the site/app we go top down. It seems more logical that the first div on top (often a navbar) would not care that there is content below to be spaced. When the second div is added, it has surroundings to be aware of above, and should react according. I suppose this thinking is more component-centric.
margin-bottom or margin-top | CSS-Tricks
- Use margin to separate the block from things outside it
- Use padding to move the contents away from the edges of the block
- it is all about concerns. Does the parent container care about its inner spacing? Or do the children care about their spacing?
Strings are bigger to store, so garbage collection will be needed sooner.
const ROBOT = 0;
const HUMAN = 1;
const SPIDER = 2;
let E_TYPE = {
Robot: ROBOT,
Human: HUMAN,
Spider: SPIDER
};
// bad
// avoid uncached strings in heavy tasks (or better in general)
if (entity.type === "Robot") {
}
// good
// the compiler can resolve member expressions
// without much deepness pretty fast
if (entity.type === E_TYPE.Robot) {
}
// perfect
// right side of binary expression can even get unfold
if (entity.type === ROBOT) {
}
No, 'function'
will be cached, and typeof
is very fast
Use someVar === undefined
over typeof someVar === 'undefined'
, as it is less work for the compiler. See this tweet.
Writing efficient JavaScript – Medium
Because these vars are created and garbage collected soon after with each render (expensive)
// BAD
render () {
let make = `Make: ${this.props.make}`;
return <div>{name}</div>;
}
// GOOD
render () {
return <div>{`Make: ${this.props.make}`}</div>;
}
// GOOD
get make () {
return `Make: ${this.props.make}`;
}
render () {
return <div>{this.make}</div>;
}