day 241 — code 365
Thu 11 Aug 2016
React / JSX
Learnt a few more gotchas today:
Default values for text inputs and checkbox inputs are different!
For text inputs:
defaultValue={defaultValue}For checkbox inputs:
defaultChecked={defaultChecked}And, also (thank you ESLint), if a boolean attribute is true, it should be omitted (only specify the attribute when using false):
defaultValue={true} // no need for this
defaultValue={false} // yep, this is neededHTML
Remembered just in time that one can reset a form by using the native DOM type=”reset” attribute for buttons inside forms!
This was a LOT / IMMEASURABLY better than having to refactor the entire component (and child components) to have their values determined by component state / Redux store.
JS
Learnt some handy tips for debugging:
Instead of manually typing a string of characters, we can use:
'*'.repeat(15);
To print objects with an indentation of 2 spaces:
JSON.stringify(obj, null, 2)