day 306 — code 365

Sat 15 Oct 2016


I was reminded today that the initial state object used to initialise the application state (kept in Redux store) is very important. This is because, if a value is being passed down as props, but hasn’t been initialised in the initial state, we will errors like this:

warning.js:36 Warning: <ComponentName> is changing an uncontrolled input of type number to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component.

This is because if a value isn’t declared in the initial state, it is undefined (there is NO value), and this will be passed down through props; the input will be initialised with NO VALUE. However, when the store receives real data from an API call, an actual value will be passed down through props, and this is what changes the input from uncontrolled to controlled.


I learnt about the delete keyword today!

I used it to remove a key from an object:

We create an object with 2 keys:

const magic = { hotdogs: 123, chocolate: 234 };

We delete a key:

delete magic.chocolate;

Leaving us with an object with just 1 key!

// { hotdogs: 123 }
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.