Zach Johnson

On my learnings of JavaScript

This is WIP - and Always will be

This is a Work in progress post that I am continually updating as I continue to deepen my knowledge of JavaScript. Most everything here are just for coming back to review, but sometimes I'll note down something new I learn here too.

Learning more about Vue

A year ago I would have said I was pretty good using Vue, now I know how much I don't really know.

Three sentence summaries:

Extrapolations:

JavaScript

General learning and knowledge about javascript

Higher Order Functions

React

Hooks

useState

EX:

function App() {
const [value, setValue] = useState(10);
}

EX 2:

function veryTimeConsuming() {
...
...
return { /* COMPLICATED STATE */ };
}

function App() {
const [value, setValue] = useState(() => veryTimeConsuming());
}

Ex 3, the set function:

function App() {
const [count, setCount] = useState(10);

return (
<div>
<button onClick={() => setCount((currentCount) => currentCount + 1)}>
+
</button>
<div>{count}</div>
</div>
);
}

EX 4, set function with multiple values in the state:

const [{ count, count2 }, setCount] = useState({ count: 10, count2: 20 });

return (
<div>
<button
onClick={() =>
setCount((currentState) => ({
...currentState,
count: currentState.count + 1,
}))
}
>
+
</button>
<div>count 1: {count}</div>
<div>count 2: {count2}</div>
</div>
);

useEffect

Whatever happens inside of this function gets called on every re-render of the component.

EX:

useEffect(() => {
console.log("mounted");
}, []);

EX 2, Cleanup:

useEffect(() => {
console.log("mounted");

// The useEffect returns this as a clean up function
return () => {
console.log("unmount");
};
}, []);
Back Home