<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Alan Montgomery's Blog - All things JavaScript and web ]]></title><description><![CDATA[I love teaching people how to code, and making coding tutorials, one of my big passions is transferring my web development/coding skills and knowledge on to people like you.]]></description><link>https://blog.alanmontgomery.co.uk</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 21:16:44 GMT</lastBuildDate><atom:link href="https://blog.alanmontgomery.co.uk/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Routing, programmatically in Ionic React]]></title><description><![CDATA[PS: I originally posted this on Ionic React Hub
Today I want to teach you how you can achieve routing programmatically in Ionic with React. There are a few different ways it can be done, but there's one way that should definitely be utilised, especia...]]></description><link>https://blog.alanmontgomery.co.uk/routing-programmatically-in-ionic-react</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/routing-programmatically-in-ionic-react</guid><category><![CDATA[React]]></category><category><![CDATA[Ionic Framework]]></category><category><![CDATA[Mobile Development]]></category><category><![CDATA[react router]]></category><category><![CDATA[navigation]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Thu, 03 Jun 2021 21:44:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1622756536396/9fdIh545k.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>PS: I originally posted this on <a target="_blank" href="https://ionicreacthub.com">Ionic React Hub</a></p>
<p>Today I want to teach you how you can achieve routing programmatically in Ionic with React. There are a few different ways it can be done, but there's one way that should definitely be utilised, especially in the day and era we live in with <code>hooks</code> and the functionality we're provided with out-of-the-box by Ionic!</p>
<p>I've found it hard in the past, along my journey to come across docs and resources in one place detailing these miniscule, specific use cases, and I want to start creating valuable, short pieces of information to help you on your Ionic React journey too, all in one place!</p>
<p>💥 Let's get started.</p>
<h2 id="useionrouter-hook">useIonRouter hook</h2>
<p>This is a <code>React hook</code> that comes baked into the Ionic Framework by default. It gives us as developers more direct control over routing in an Ionic React applicaiton. </p>
<p>All we need to do is import it;</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useIonRouter } <span class="hljs-keyword">from</span> <span class="hljs-string">"@ionic/react"</span>;
</code></pre>
<p>Now, because this is a hook, we need to obey by the rule of hooks in React. What's that?</p>
<blockquote>
<p>You must only call hooks inside inside a function. Never inside a loop, or other conditional statement etc and always at the top level.</p>
</blockquote>
<p>Just think of it like your standard local <code>useState</code> hook call within a component that you're probably already familiar with.</p>
<h2 id="initializing-the-hook">Initializing the hook</h2>
<p>Lets say we have a component called <code>Page1.js</code> and at the top of this functional component we can initialize our hook like so;</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useIonRouter } <span class="hljs-keyword">from</span> <span class="hljs-string">"@ionic/react"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> Page1 = <span class="hljs-function">() =&gt;</span> {

    <span class="hljs-keyword">const</span> router = useIonRouter();
}
</code></pre>
<h2 id="methods-of-the-useionrouter-hook">Methods of the useIonRouter hook</h2>
<p>We have access to a few very useful built-in methods we can use to navigate through our app, these are;</p>
<ol>
<li><p><code>goBack()</code>
This method will navigate backwards in history, using the IonRouter to determine history. It accepts one argument for an optional custom transition if wanted </p>
<ul>
<li><code>animationBuilder?: AnimationBuilder</code>- <strong>*Optional</strong> - A custom transition animation to use*</li>
</ul>
</li>
<li><p><code>push()</code>
This method allows us to push a route into the history of the router. This also accepts a few additional arguments to pass to the method. These are;</p>
<ul>
<li><p><code>pathname: string</code> </p>
<ul>
<li><em>The path to navigate to</em> - e.g. <code>/page2</code>.</li>
</ul>
</li>
<li><p><code>routerDirection?: RouterDirection</code> </p>
<ul>
<li><strong>*Optional</strong> - The RouterDirection to use for transition purposes, defaults to 'forward', can also be 'back', 'none' and 'root'.*</li>
</ul>
</li>
<li><p><code>routeAction?: RouteAction</code></p>
<ul>
<li><strong>*Optional</strong> - The RouteAction to use for history purposes, defaults to 'push', but can also be 'pop' and 'replace'.*</li>
</ul>
</li>
<li><p><code>routerOptions?: RouterOptions</code></p>
<ul>
<li><strong>*Optional</strong> - Any additional parameters to pass to the route.*</li>
</ul>
</li>
<li><p><code>animationBuilder?: AnimationBuilder</code></p>
<ul>
<li><strong>*Optional</strong> - A custom transition animation to use.*</li>
</ul>
</li>
</ul>
</li>
<li><p><code>canGoBack()</code>
Determines if there are any additional routes in the the Router's history. However, routing is not prevented if the browser's history has more entries. Returns true if more entries exist, false if not.</p>
</li>
<li><p><code>routeInfo()</code>
This method will return some information about the <em>current</em> route.</p>
</li>
</ol>
<p>Now let's see how we can implement this in a real piece of code, following on from earlier in the post;</p>
<p><strong>NOTE</strong></p>
<blockquote>
<p>Let's assume that all routes and pages/tabs and main <code>IonApp</code> is already set up and working. This is simply a demonstration of how to use the router from within a component/page.</p>
</blockquote>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { useIonRouter } <span class="hljs-keyword">from</span> <span class="hljs-string">"@ionic/react"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> Page1 = <span class="hljs-function">() =&gt;</span> {

    <span class="hljs-comment">//    Initializing our router</span>
    <span class="hljs-keyword">const</span> router = useIonRouter();

    <span class="hljs-comment">//    A simple, hard-coded navigation</span>
    <span class="hljs-keyword">const</span> simpleNavigate = <span class="hljs-function">() =&gt;</span> {

        router.push(<span class="hljs-string">"/page2"</span>, <span class="hljs-string">"forward"</span>, <span class="hljs-string">"push"</span>);
    }

    <span class="hljs-comment">//    A more usable, dynamic navigate function</span>
    <span class="hljs-comment">//    Passing in the path and direction</span>
    <span class="hljs-comment">//    Working out the action based on direction</span>
    <span class="hljs-keyword">const</span> dynamicNavigate = <span class="hljs-function">(<span class="hljs-params">path, direction</span>) =&gt;</span> {

        <span class="hljs-keyword">const</span> action = direction === <span class="hljs-string">"forward"</span> ? <span class="hljs-string">"push"</span> : <span class="hljs-string">"pop"</span>;
        router.push(path, direction, action);
    }

    <span class="hljs-comment">//    Checking if we can go back</span>
    <span class="hljs-comment">//    Before calling the goBack() method</span>
    <span class="hljs-keyword">const</span> navigateBack = <span class="hljs-function">() =&gt;</span> {

        <span class="hljs-keyword">if</span> (router.canGoBack()) {

            router.goBack();
        }
        <span class="hljs-comment">//     else...</span>
    }

    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">IonPage</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">IonContent</span>&gt;</span>

                //    Calling a function which calls the push method
                <span class="hljs-tag">&lt;<span class="hljs-name">IonButton</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"primary"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{</span> <span class="hljs-attr">simpleNavigate</span> }&gt;</span>
                    Go to Page 2
                <span class="hljs-tag">&lt;/<span class="hljs-name">IonButton</span>&gt;</span>

                //    Calling a function which calls the push method
                //    But is dynamic, and we have control
                <span class="hljs-tag">&lt;<span class="hljs-name">IonButton</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"primary"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{</span> () =&gt;</span> dynamicNavigate("/page3", "forward") }&gt;
                    Go to X
                <span class="hljs-tag">&lt;/<span class="hljs-name">IonButton</span>&gt;</span>

                //    Calling a method of the router directly
                <span class="hljs-tag">&lt;<span class="hljs-name">IonButton</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"secondary"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{</span> () =&gt;</span> router.goBack() }&gt;
                    Go Back
                <span class="hljs-tag">&lt;/<span class="hljs-name">IonButton</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">IonContent</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">IonPage</span>&gt;</span></span>
    );
}
</code></pre>
<p>Awesome, right? That's pretty much it! You can see how easy Ionic have made it for us with this <code>useIonRouter</code> hook, however sometimes having a little context is good!</p>
<p>I really hope you enjoyed this little tutorial on routing programmatically in Ionic React! Be sure to sign up below to receive emails about new posts like these directly and all future content!</p>
<p>Let me know what you think via <a target="_blank" href="https://twitter.com/93alan">Twitter</a></p>
<p>If you’re interested in learning more about Ionic and React you could also check out my website</p>
<p><a target="_blank" href="https://ionicreacthub.com">Ionic React Hub</a></p>
<p>I post UI Examples, tutorials and posts there. As well as share some valuable content and resources!</p>
<p><img src="https://ionicreacthub.com/social.png" alt="IRH" /></p>
<p>See you in the next one 👋</p>
]]></content:encoded></item><item><title><![CDATA[Javascript ES2021 - Features to be included this year in ES12]]></title><description><![CDATA[ES12 is planned to be released in June 2021. So we're a little bit off yet, but there are some cool things that have been announced already, one of which is going to be awesome!
Here's a breakdown of what I'm going to briefly cover:

Numeric separato...]]></description><link>https://blog.alanmontgomery.co.uk/javascript-es2021-features</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/javascript-es2021-features</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Mobile Development]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Wed, 24 Mar 2021 11:38:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1616583917258/xbyNx-o7i.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>ES12 is planned to be released in June 2021</strong>. So we're a little bit off yet, but there are some cool things that have been announced already, one of which is going to be awesome!</p>
<p>Here's a breakdown of what I'm going to briefly cover:</p>
<ul>
<li>Numeric separators</li>
<li>String.prototype.replaceAll()</li>
<li>Logical assignment operators</li>
<li>Promise.any</li>
<li>WeakRef</li>
</ul>
<h1 id="numeric-separators">Numeric Separators</h1>
<p>It can be quite hard to read a large number when written in Javascript for example;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> population = <span class="hljs-number">81760456</span>;
</code></pre>
<p>Looking at this number right away, it's not easy to see that it is in fact <code>81 million</code>, you spend a second just figuring out how many digits there are in your head before you come to that conclusion.</p>
<blockquote>
<p>With <strong>ES12</strong> we will have the ability to separate out our numbers when assigning a value to a variable like so;</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> population = <span class="hljs-number">81</span>_760_456;
</code></pre>
<p>It's a lot more readable and easier to understand right? Using the <em>underscore</em> character, we'll be able to neatly separate numbers and can now clearly see that this number is 81 million.......</p>
<h1 id="stringprototypereplaceall">String.prototype.replaceAll()</h1>
<p>This is a big win! I'm sure all JS devs and even all web developers generically will agree on this point! It's not a HUGE benefit, but it's definitely a neat addition.</p>
<p>Rightly so, as the function name suggests, we will be able to replace <strong>all occurrences in a string</strong>! Previously, as you'll know, you would have had to use the <code>replace()</code> function with a regex or pattern like;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> sentence = <span class="hljs-string">"Looking outside I can see 5 flowers, 1 flower is red, another flower is blue, and another is green."</span>;
sentence = sentence.replace(<span class="hljs-regexp">/flower/g</span>, <span class="hljs-string">'car'</span>);

<span class="hljs-comment">// This would replace all the instances of "flower" with "car"</span>
</code></pre>
<p>With the new <code>replaceAll</code>, there is no need for our regex now and we could simply do;</p>
<pre><code class="lang-javascript">sentence = sentence.replaceAll(<span class="hljs-string">"flower"</span>, <span class="hljs-string">"car"</span>);
</code></pre>
<blockquote>
<p>Why didn't this ever exist in the first place? 😅</p>
</blockquote>
<h1 id="logical-assignment-operators">Logical assignment operators</h1>
<p>We will have three introductions of new logical operators;</p>
<ol>
<li>&amp;&amp;= (AND AND EQUALS)</li>
<li>||= (OR OR EQUALS)</li>
<li>??= (QUESTION QUESTION EQUALS)</li>
</ol>
<h2 id="and-and-and-equals">&amp;&amp;= (AND AND EQUALS)</h2>
<p>This operator will perform an assignment when the left is a true value, for example;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> var1 = <span class="hljs-number">100</span>;
<span class="hljs-keyword">let</span> var2 = <span class="hljs-number">150</span>;

var1 &amp;&amp;= var2;

<span class="hljs-comment">// Just like saying if var1 then var1 = var2</span>
<span class="hljs-keyword">if</span> (var1) {
   var1 = var2
}
</code></pre>
<h2 id="or-or-or-equals">||= (OR OR EQUALS)</h2>
<p>The new logical OR is like the opposite of the above - the assignment will happen when the left is a false value, for example;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> var1 = <span class="hljs-literal">null</span>;
<span class="hljs-keyword">let</span> var2 = <span class="hljs-number">150</span>;

var1 ||= var2;

<span class="hljs-comment">// Just like saying if !var1 then var1 = var2</span>
<span class="hljs-keyword">if</span> (!var1) {
   var1 = var2
}

<span class="hljs-comment">// Which means var1 will now hold the value of var2 in this case</span>
</code></pre>
<h2 id="question-question-equals">??= (QUESTION QUESTION EQUALS)</h2>
<p>With this new operator, the assignment happens when the left operand is null or it is undefined. For example;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> var1 = <span class="hljs-literal">null</span>;
<span class="hljs-keyword">let</span> var2 = <span class="hljs-number">150</span>;

var1 ??= var2;

<span class="hljs-comment">// Just like saying if var1 is null or undefined then var1 = var2</span>
<span class="hljs-keyword">if</span> (var1 == <span class="hljs-literal">null</span> || var1 == <span class="hljs-literal">undefined</span>) {
   var1 = var2
}

<span class="hljs-comment">// Which means var1 will now hold the value of var2 in this case as var1 is actually null.</span>
</code></pre>
<p><em>NOTE: It only checks for null or undefined and not for example a FALSE value.</em></p>
<h1 id="promiseany">Promise.any</h1>
<p>This new method will take multiple promises and resolves whenever any of the promises are resolved. What does this mean?</p>
<p><code>Promise.any()</code> will take whatever promise resolves first. If no promise resolves then we'll get thrown an <code>error</code>.</p>
<h1 id="weakref">WeakRef</h1>
<p>Also known as <code>Weak References</code> - this can be used to hold a weak reference to another object.</p>
<p>You can create a Weak Reference by using new WeakRef, and you can read a reference by calling the deref() method. A simple example would be;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> largeObject = <span class="hljs-keyword">new</span> WeakRef({
     <span class="hljs-attr">name</span>: <span class="hljs-string">"CacheMechanism"</span>,
     <span class="hljs-attr">type</span>: <span class="hljs-string">"Cache"</span>,
     <span class="hljs-attr">implementation</span>: <span class="hljs-string">"WeakRef"</span>
});

largeObject.deref();
largeObject.deref().name;
largeObject.deref().type;
largeObject.deref().implementation;
</code></pre>
<p>My favourite feature coming in ES12 is definitely the <code>replaceAll</code> method, which will save a lot of confusion is nothing else. I also like the new operators. </p>
<p>What's your favourite?</p>
<p>Are you on Twitter? Let's connect! <a target="_blank" href="https://twitter.com/93alan">@93alan</a></p>
<p>I also have a <a target="_blank" href="https://bit.ly/alanmontgomerycoding">YouTube channel</a> where I post coding tutorials, tips, tricks, reviews and more! I'd love to see you over there, I'd appreciate it:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://bit.ly/alanmontgomerycoding">https://bit.ly/alanmontgomerycoding</a></div>
]]></content:encoded></item><item><title><![CDATA[Mobile DevCast - A podcast dedicated to mobile app development and web native technologies]]></title><description><![CDATA[This is something I've been wanting to do for quite some time now. Start a podcast on the things I love in the development world.
That is mobile development. Both for the web and for native devices like iOS and Android. The only difference is, I use ...]]></description><link>https://blog.alanmontgomery.co.uk/mobiledevcast-web-native-podcast</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/mobiledevcast-web-native-podcast</guid><category><![CDATA[podcast]]></category><category><![CDATA[Mobile apps]]></category><category><![CDATA[React]]></category><category><![CDATA[Ionic Framework]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Sun, 24 Jan 2021 22:14:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1611526480810/UmrsYBnCS.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is something I've been wanting to do for quite some time now. Start a podcast on the things I love in the development world.</p>
<p>That is mobile development. Both for the web and for native devices like iOS and Android. The only difference is, I use web native technology like Ionic, React and CapacitorJS to develop cross platform mobile apps and manage one codebase. I've been a Mobile Team Lead now using Ionic React to develop mobile apps for local government for 2.5 years, with over 7 years experience of full stack development under my belt.</p>
<p>I love sharing knowledge, and this is where the idea came from about starting a podcast to discuss the leading, cutting edge modern web tech known as web native.</p>
<p>If you'd like to sign up to be notified of the first episode release you can visit the Mobile DevCast website below:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://mobiledevcast.com">https://mobiledevcast.com</a></div>
]]></content:encoded></item><item><title><![CDATA[How to easily understand Flexbox CSS - (Part 2)]]></title><description><![CDATA[Welcome back to this mini series. In Part 1 we looked at the main display property to activate or enable flexbox css on a contrainer element. I also talked about the different types of flex-direction you could use. If you missed it you can read Part ...]]></description><link>https://blog.alanmontgomery.co.uk/how-to-easily-understand-flexbox-css-part-2</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/how-to-easily-understand-flexbox-css-part-2</guid><category><![CDATA[flexbox]]></category><category><![CDATA[CSS]]></category><category><![CDATA[css flexbox]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Sat, 14 Nov 2020 01:36:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1605317790809/sJ2wT4T_z.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome back to this mini series. In <a target="_blank" href="https://blog.alanmontgomery.co.uk/how-to-easily-understand-flexbox-css-part-1">Part 1</a> we looked at the main <code>display</code> property to activate or enable flexbox css on a contrainer element. I also talked about the different types of <code>flex-direction</code> you could use. If you missed it you can read Part 1 below, or I also created a <a target="_blank" href="https://www.youtube.com/watch?v=MEWWFZx3h44">YouTube video</a> to accompany it if you'd prefer that.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://blog.alanmontgomery.co.uk/how-to-easily-understand-flexbox-css-part-1">https://blog.alanmontgomery.co.uk/how-to-easily-understand-flexbox-css-part-1</a></div>
<p>Let's get started with Part 2...</p>
<h1 id="what-are-you-going-to-learn">What are you going to learn?</h1>
<p>It's all well and good being able to enable flexbox css, create a flex container, and use CSS to tell our elements which way to flow (row or column), however you can also <strong>justify</strong> the content of the whole container as well. This makes it very powerful and easy to position items within a flex container with one bit of CSS.</p>
<h2 id="justify-content">Justify Content</h2>
<p>By specifying the <code>justify-content</code> property on a flex container, you can position the <strong>entire contents</strong> of the container (all child elements inside the parent element). The key point here for this property is <em>the entire contents</em>.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">justify-content</span>:
}
</code></pre>
<p>You might be familiar with this kind of positioning when using <code>float</code> in CSS or even <code>margin</code> to space items (elements) out.</p>
<h3 id="how-can-you-justify-content-in-flexbox-css">How can you justify content in flexbox css?</h3>
<p>There are lots of different values for this property. In fact, there are 16 official flexbox justify content values. That's a lot right? Well, we only need to focus on 6 of them, the most important values and most commonly/needed options. Take a look below...</p>
<h3 id="flex-start">Flex Start</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">justify-content</span>: flex-start;
}
</code></pre>
<p>This value for <code>justify-content</code> will align the entire contents of the flex container to the <strong>start</strong> of the container. There won't be any padding or spacing taken into consideration in this case, all items will just be pushed to the start.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605315684568/V7b4rftpP.png" alt="Screenshot 2020-11-14 at 01.00.58.png" /></p>
<h3 id="flex-end">Flex End</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">justify-content</span>: flex-end;
}
</code></pre>
<blockquote>
<p>You've probably guessed it by now right? If you did, leave a comment!</p>
</blockquote>
<p>This value for <code>justify-content</code> is similar to the <code>flex-start</code> value however it will align the entire contents of the flex container to the <strong>end</strong> of the container.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605315877915/x9s9k3okq.png" alt="Screenshot 2020-11-14 at 01.01.09.png" /></p>
<h3 id="center">Center</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">justify-content</span>: center;
}
</code></pre>
<p>You can also align the entire contents of a flex container into the center on the <em>horizontal</em> axis. Again, quite like the first two options/values, the items inside the flex container will not have any padding or margin around them, unless specified obviously.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605316082447/Xr_YIyBde.png" alt="Screenshot 2020-11-14 at 01.07.49.png" /></p>
<p>...The next three <code>justify-content</code> values are a bit more powerful and popular for aligning content in a nice readable format.</p>
<h3 id="space-between">Space Between</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">justify-content</span>: space-between;
}
</code></pre>
<p>Using this value, the <code>space-between</code> justify-content value will space out the items inside the flex container throughout the whole row or column. For example if you had three items (elements) inside a flex container, the first one would be aligned to the start (<em>flex-start</em>), the second to the center (<em>center</em>) and the third to the end (<em>flex-end</em>).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605316320690/_YPAbt0R_.png" alt="Screenshot 2020-11-14 at 01.11.54.png" /></p>
<h3 id="space-around">Space Around</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">justify-content</span>: space-around;
}
</code></pre>
<p>This value will ensure that there is adequate space <strong>around</strong> the items within the flex container. For example, there will be equal amounts of space from the start of the container compared to the end of the container, with the second item being in the center.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605316533191/U0y79NR0d.png" alt="Screenshot 2020-11-14 at 01.15.27.png" /></p>
<h3 id="space-evenly">Space Evenly</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">justify-content</span>: space-evenly;
}
</code></pre>
<p>Quite like the other two; <code>space-between</code> and <code>space-around</code>, the <code>space-evenly</code> will also provide spacing or "padding" around the items inside the flex container. The only difference with this value is that all spacing inside the flex container will be <strong>equal</strong> or <em>evenly</em> distributed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605316561093/fXVmoTFdr.png" alt="Screenshot 2020-11-14 at 01.15.50.png" /></p>
<p>Those are the main, most important values that you should focus on when using the <code>justify-content</code> CSS property using flexbox. Feel free to look into the other options available however the only other ones that may be of use would be <code>baseline</code> most likely which would align items at the bottom base of the flex container.</p>
<p>I hope you enjoyed Part 2 of this mini series! Are you understanding flexbox CSS a little more? Please let me know by replying if you are! 🧙🏻‍♂️</p>
<p>Stay tuned for Part 3!</p>
<p>Are you on Twitter? Let's connect! <a target="_blank" href="https://twitter.com/93alan">@93alan</a></p>
<p>I also have a <a target="_blank" href="https://bit.ly/alanmontgomerycoding">YouTube channel</a> where I post coding tutorials, tips, tricks, reviews and more! I'd love to see you over there, I'd appreciate it:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://bit.ly/alanmontgomerycoding">https://bit.ly/alanmontgomerycoding</a></div>
]]></content:encoded></item><item><title><![CDATA[How to easily understand Flexbox CSS - (Part 1)]]></title><description><![CDATA[In this mini-series, I will be taking you through how to use flexbox CSS, in a simple, easy to understand way. You can really empower your projects and websites with the use of flexbox CSS and reduce your lines of code drastically. I have also releas...]]></description><link>https://blog.alanmontgomery.co.uk/how-to-easily-understand-flexbox-css-part-1</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/how-to-easily-understand-flexbox-css-part-1</guid><category><![CDATA[CSS]]></category><category><![CDATA[flexbox]]></category><category><![CDATA[css flexbox]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Mon, 09 Nov 2020 00:24:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1604884175281/Wd5pu-Bw3.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this mini-series, I will be taking you through how to use flexbox CSS, in a simple, easy to understand way. You can really empower your projects and websites with the use of flexbox CSS and reduce your lines of code drastically. I have also released a video-based tutorial series over on my <a target="_blank" href="https://bit.ly/alanmontgomerycoding">YouTube</a> so if you'd prefer a video, check that below! Ok... Let's get into it.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=MEWWFZx3h44">https://www.youtube.com/watch?v=MEWWFZx3h44</a></div>
<h1 id="what-is-flexbox-css">What is Flexbox CSS?</h1>
<p>Flexbox CSS is a one dimensional layout model/method used for laying out items (HTML elements) in a row or column fashion (horizontal or vertical).</p>
<h2 id="why-flexbox-css">Why Flexbox CSS?</h2>
<p>Long gone are the days of using <code>float</code> and <code>position</code> in CSS to create layouts and responsive layouts. Utilising flexbox allows you to create fully <strong>responsive</strong>, mobile first layouts without needing to write lots of different media queries.</p>
<h2 id="display">Display</h2>
<p>The most important CSS property in flexbox is the <strong>display</strong> property. This is how we define a "flexbox container". Familiar display properties include <em>block</em>, <em>inline</em>, <em>inline-block</em> etc etc. Flex is no different, it can be defined like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">display</span>: flex;
}
</code></pre>
<h2 id="container">Container</h2>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Our flex container is typically a block level element, usually like a div for example. Refer to the below image; I have defined a flex container and inside my flex container, I have three more divs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1604881496142/fnYjCju9S.png" alt="Flexbox container / Flex container" /></p>
<h2 id="items">Items</h2>
<p>These are called flex items. Each child inside a flex container is referred to as an "item". You can style these individually again, using flexbox CSS if wanted and we'll get into the specifics of this in the next part.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1604881547911/oHOA4hd7z.png" alt="Flexbox items / Flex items" /></p>
<h2 id="flex-direction">Flex Direction</h2>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>:
}
</code></pre>
<p>The next important CSS property in terms of flexbox is the <code>flex-direction</code> property. This allows you to specify which direction you want to place the items inside the flex container. There are four values which can be used for the <code>flex-direction</code> property, either in a row or a column (<em>e.g. horizontally or vertically</em>).</p>
<h3 id="row">Row</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>: row;
}
</code></pre>
<p>By default, a flex container will automatically have the flex direction of row. Items inside a row direction flex container will be displayed <em>left to right</em> (LTR), your first item will be the first placed element on the display.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1604881578319/WinXtcAhZ.png" alt="Flex direction row" /></p>
<h3 id="row-reverse">Row Reverse</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>: row-reverse;
}
</code></pre>
<p>The <code>row-reverse</code> value for <code>flex-direction</code> is similar to the <code>row</code> value, however the items inside a row-reverse direction flex container will be displayed <em>right to left</em> (RTL), so your first item will now become the last for example.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1604881606985/r6yklzUvS.png" alt="Flex direction row-reverse" /></p>
<h3 id="column-and-column-reverse">Column and Column Reverse</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {

    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>: column | column-reverse;
}
</code></pre>
<p>The next type of <code>flex-direction</code> you can specify is in the vertical axis in the form of columns. First of all with the <code>column</code> value, similar to the <code>row</code> value but placed <em>top to bottom</em> (TTB). Alternatively you can use the <code>column-reverse</code> value which again, is similar to <code>row-reverse</code> but displayed <em>bottom to top</em> (BTT).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1604881638561/5U3hUwFeJ.png" alt="Flex direction column and column reverse" /></p>
<p>Hope you enjoyed part 1 of my easy to understand flexbox CSS tutorial. It really is that simple to get started using it. In the next part we'll look at some more specific properties we can use to <code>justify-content</code> to space out flex items inside our flex containers!</p>
<p>Please leave a comment and a reaction to this post if you enjoyed it! Also, I have a <strong>YouTube</strong> channel where I'm posting lots of coding tutorials, tips, tricks, reviews and more, would love to see you there:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://bit.ly/alanmontgomerycoding">https://bit.ly/alanmontgomerycoding</a></div>
<p>See you in the next part!</p>
]]></content:encoded></item><item><title><![CDATA[Using React Context API with NextJS]]></title><description><![CDATA[One huge pain point in React (and NextJS) is having to pass props through multi-level components. The bigger the application or project gets, the more painful this becomes. This is because of how React is structured, in a tree like fashion with data ...]]></description><link>https://blog.alanmontgomery.co.uk/using-react-context-api-with-nextjs</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/using-react-context-api-with-nextjs</guid><category><![CDATA[Next.js]]></category><category><![CDATA[software development]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Mon, 02 Nov 2020 21:49:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1604267816970/GxdaWR0TS.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>One huge pain point in React (and NextJS) is having to pass props through multi-level components. The bigger the application or project gets, the more painful this becomes. This is because of how React is structured, in a tree like fashion with data only flowing in one direction.</p>
<p>There are multiple ways to solve this with things like</p>
<ul>
<li>React Redux</li>
<li>MobX</li>
<li>...and more</li>
</ul>
<p>One of the newer ways, especially introduced with React Hooks, is the React Context API.</p>
<h1 id="what-is-the-context-api">What is the Context API?</h1>
<blockquote>
<p>It is a way to enable multiple components (or pages in NextJS) to share global variables and data without having to "pass" these as props. Think of it like a global "object" which stores data.</p>
</blockquote>
<p>Although the Context API can be used for most cases, it shouldn't be used for <strong>everything</strong>. A close observation on component re-renders should be taken when using Context API to prevent any compromising leaks or inefficiencies.</p>
<p>That being said, we can easily implement Context API using React Hooks into <strong>NextJS</strong>.</p>
<p><em>Let's step through the creation of a simple custom Auth to allow our NextJS app to see the logged in status of a user, and the users details throughout every component and page.</em></p>
<h2 id="1-creating-a-provider-component">1. Creating a <strong>Provider</strong> component</h2>
<p>This component will <strong>provide</strong> our defined data to the rest of our app.</p>
<pre><code><span class="hljs-keyword">import</span> { useState, createContext } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> AuthContext = createContext();

<span class="hljs-keyword">const</span> AuthProvider = <span class="hljs-function">(<span class="hljs-params">{ children }</span>) =&gt;</span> {

    <span class="hljs-keyword">const</span> [ loggedIn, setLoggedIn ] = useState(<span class="hljs-literal">false</span>);
    <span class="hljs-keyword">const</span> [ userDetails, setUserDetails ] = useState([]);

    <span class="hljs-keyword">const</span> login = <span class="hljs-function"><span class="hljs-params">value</span> =&gt;</span> {

        setLoggedIn(<span class="hljs-literal">true</span>);
        setUserDetails({
            <span class="hljs-attr">name</span>: <span class="hljs-string">"Alan"</span>,
            <span class="hljs-attr">notifications</span>: <span class="hljs-number">3</span>
        });
    }

    <span class="hljs-keyword">const</span> logout = <span class="hljs-function"><span class="hljs-params">value</span> =&gt;</span> {

        setLoggedIn(<span class="hljs-literal">false</span>);
        setUserDetails([]);
    }

    <span class="hljs-keyword">const</span> contextValue = {

        <span class="hljs-attr">status</span>: {

            loggedIn,
            login,
            logout
        },
        <span class="hljs-attr">user</span>: {

            userDetails,
            setUserDetails
        }
    };

    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">AuthContext.Provider</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{</span> <span class="hljs-attr">contextValue</span> }&gt;</span>
            { children }
        <span class="hljs-tag">&lt;/<span class="hljs-name">AuthContext.Provider</span>&gt;</span></span>
    );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> AuthProvider;
</code></pre><ul>
<li>The <code>createContext()</code> method, allows us to create a context object to hold some global data.</li>
<li>I've set up some state variables using the <a target="_blank" href="https://blog.alanmontgomery.co.uk/how-to-use-the-usestate-hook-in-react">useState hook</a>, including a variable for logged in, and a variable for the user details.</li>
<li>Custom login/logout functions created to set the <em>logged in status</em> and also the user details (for this example, when logging in, we just mimic it with hard-coded values).</li>
<li>I've set up a <code>contextValue</code> object which we can use to structure our global data nicely, for example, for the <code>loggedIn</code> variable and functions, I've called it <em>status</em>, which means, further down the React Tree of components we will be able to access the loggedIn state variable like <code>AuthContext.status.loggedIn</code> which we will see shortly.</li>
<li>A Provider component will always return the children, in our case, the children will be the component or page, wrapped with our <code>AuthContext.Provider</code>.</li>
</ul>
<p>We can save this Provider in a <code>providers</code> folder or <code>utils</code> or anything you like.</p>
<h2 id="2-wrap-our-app-root-component-with-our-context">2. Wrap our app root component with our Context</h2>
<p>In traditional React, we would wrap our <code>&lt;App /&gt;</code> with the Context, however, in NextJS, this doesn't exist. Instead we can provide a custom App component by creating a file in the root folder called <code>_app.js</code>, it should already be present in most cases.</p>
<p>Let's first import our <code>AuthProvider</code> component:</p>
<pre><code><span class="hljs-keyword">import</span> AuthProvider <span class="hljs-keyword">from</span> <span class="hljs-string">"../utils/AuthProvider"</span>;
</code></pre><p>Then wrap our <code>&lt;Component .... /&gt;</code> with this Provider. At this point then the Component will be passed as a child to our Context API Provider, which we saw above with the return of children.</p>
<pre><code><span class="hljs-keyword">return</span> (

    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">AuthProvider</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Component</span> { <span class="hljs-attr">...pageProps</span> } /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">AuthProvider</span>&gt;</span></span>
);
</code></pre><h2 id="3-import-usecontext-and-our-custom-authcontext-into-indexjs">3. Import useContext and our custom AuthContext into index.js</h2>
<p>In order to use the values from our Provider, we need to utilise the <code>useContext</code> hook from React, as well as importing our <code>AuthContext</code> we created earlier:</p>
<pre><code><span class="hljs-keyword">import</span> { useContext } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { AuthContext } <span class="hljs-keyword">from</span> <span class="hljs-string">"../utils/AuthProvider"</span>;
</code></pre><p>Inside our Home (or any other) component/page we can easily grab all of our Context global variables using the above hook, and destruct our custom, nicely formatted values like this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> { status, user } = useContext(AuthContext);
</code></pre>
<p>At this point, we now have access, globally to the variables we set up earlier, e.g. <code>{ status.loggedIn }</code> will return the loggedIn value held in that state variable.</p>
<h2 id="4-setting-up-a-simple-login-logout-ui">4. Setting up a simple login / logout UI</h2>
<p>Using our global Context API variables/functions and data, we can now manipulate our UI based on this, let's set up a very basic, mimicked example of this:</p>
<blockquote>
<p>Example of our return in index.js</p>
</blockquote>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">main</span> <span class="hljs-attr">className</span>=<span class="hljs-string">{styles.main}</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">className</span>=<span class="hljs-string">{styles.title}</span>&gt;</span>
        Welcome to <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://nextjs.org"</span>&gt;</span>Next.js!<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>
        Status:<span class="hljs-symbol">&amp;nbsp;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">color:</span> <span class="hljs-attr">status.loggedIn</span> ? "<span class="hljs-attr">green</span>" <span class="hljs-attr">:</span> "<span class="hljs-attr">red</span>" }}&gt;</span>
            { status.loggedIn ? "Logged in" : "Not Logged In" }
        <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span>

    { status.loggedIn &amp;&amp; <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{</span> <span class="hljs-attr">status.logout</span> }&gt;</span>Logout<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span> }
    { !status.loggedIn &amp;&amp; <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{</span> <span class="hljs-attr">status.login</span> }&gt;</span>Login<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span> }

    { status.loggedIn &amp;&amp;
        <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Hi { user.userDetails.name }<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
    }
<span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre><p>Logged out state:
<img src="https://i.ibb.co/bXWrfSc/Screenshot-2020-11-01-at-22-48-12.png" alt="NextJS logged out state" /></p>
<p>Logged in state:
<img src="https://i.ibb.co/b39zs5T/Screenshot-2020-11-01-at-22-48-22.png" alt="NextJS logged in state" /></p>
<p>Keep in mind, our Context API global "object" or data is accessible by every page/component. So in this case, if we were to navigate to <code>/account</code> for example, the state would be retained and accessible in the same, global way.</p>
<p>This was a very very basic example of how to set up a Context API provider, and inject it into our NextJS app, then use the accessible functions and data based on the state, I hope this helps anyone, if it did, leave a little reaction on this post, greatly appreciated!</p>
<p>I've also recently started a YouTube channel. I'd love to see you over there and I welcome new subscribers. I'm posting coding tutorials, mostly on JavaScript, React and NextJS! 👇👇👇👇</p>
<p><a target="_blank" href="https://bit.ly/alanmontgomerycoding">Alan Montgomery - Coding Tutorials</a></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://bit.ly/alanmontgomerycoding">https://bit.ly/alanmontgomerycoding</a></div>
<p>Thanks for reading! Leave a comment below if you liked this!</p>
]]></content:encoded></item><item><title><![CDATA[Programming is like building Lego blocks]]></title><description><![CDATA[This may seem like a weird thing to compare programming or coding to, but it's so true, for a few reasons.
Building upon what you've done already
When you have a piece of code, you can stop and continue building upon your solution at any time - you'r...]]></description><link>https://blog.alanmontgomery.co.uk/programming-is-like-building-lego-blocks</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/programming-is-like-building-lego-blocks</guid><category><![CDATA[software development]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[React]]></category><category><![CDATA[Web Design]]></category><category><![CDATA[coding]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Sat, 31 Oct 2020 19:24:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1604172462573/597abudH8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This may seem like a weird thing to compare programming or coding to, but it's so true, for a few reasons.</p>
<h1 id="building-upon-what-youve-done-already">Building upon what you've done already</h1>
<p>When you have a piece of code, you can stop and continue building upon your solution at any time - you're not forced to finish all of your code at once - you can pause and come back to it at any point - however if you stop at a point when your code isn't complete in working order then it'll obviously be broken / unfinished. The same goes for Lego - you can build something then come back to it and continue however it'll be unfinished if you leave it.</p>
<h1 id="multiple-ways-of-building-things">Multiple ways of building things</h1>
<p>There are so many different ways to build certain solutions - more efficient ways, shorter ways (in terms of lines of code), modern ways, old school or "traditional" ways etc. They all have one thing in common - they all achieve the same end goal. However one solution or method may be better than another due to certain factors like efficiency, speed, performance etc.</p>
<h1 id="consistency-and-maintainability">Consistency and maintainability</h1>
<p>Building and developing consistent code ensures the integrity of your website or product in the long term. If you continue to use proven working patterns and techniques then it's going to be future proof. It also keeps your code alot neater and makes it more readable. Looking at the maintainability factor - this means that you can continue to come back to your code and make easy and fast changes to the code without having to touch core functionality. This also applies to if another developer down the line comes on board and tries to maintain your code - the more consistent and maintainable your code is then the easier it's going to be to be picked up by someone else.</p>
<p>All of these points can be applied directly to Lego - and although it is slightly a weird comparison - it definitely does fit together. If you ever need to bring yourself back to basics for some scope or to realign your vision of a project then think of this post. </p>
<blockquote>
<p>Can you build upon the code you're writing? Is your code consistent and maintainable? Have you figured out the best way to write the solution? </p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[The importance of planning a website]]></title><description><![CDATA[This is probably one of the most important steps in the whole web development process. Aside from all the coding, styling and technical things, we as web developers have to do - we also have to plan out and think about how we want our site to look li...]]></description><link>https://blog.alanmontgomery.co.uk/the-importance-of-planning-a-website</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/the-importance-of-planning-a-website</guid><category><![CDATA[software development]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[React]]></category><category><![CDATA[planning]]></category><category><![CDATA[Developer]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Fri, 30 Oct 2020 08:23:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1604046359459/uTRtuar-m.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is probably one of the most important steps in the whole web development process. Aside from all the coding, styling and technical things, we as web developers have to do - we also have to plan out and think about how we want our site to look like in the end. Especially for freelancers or independent web developers.</p>
<h1 id="building-a-house">Building a house</h1>
<p>Think of building a house... Do you think the builders just randomly start building a house by placing bricks and wood? Do you think it just magically all fits together? No - definitely not! It has been planned out, sketched out and carefully decided upon how to build it, what materials needed, and what features the house will have.</p>
<p>This is almost the same way we should think about when planning a website. The same way with the house, we need to plan out what layout we will use, colours, functionality included, images or if we will use any additional styling resources and if there will be any forms or input capture, the list goes on...</p>
<h1 id="colours">Colours</h1>
<p>Deciding on a colour scheme/palette for your website beforehand will really help save time down the line when you're actually coding and developing your web site. Decide on a dominant colour and a contrasting colour, also decide on a few different variants of these colours to act as button hovers, links etc, as well as text colours.</p>
<h1 id="font-family">Font family</h1>
<p>It's a good idea to figure out initially as well what font you want your website to use. You can download this font and have it ready for when you're developing. The font really does say a lot about a website so this part of the planning phase should be given some thought to if the font is readable, easy on the eye and fits its purpose. E.g. If it's a professional website or a portfolio, you will want a nice professional looking font. In comparison, if it was a fun, joke style website, then maybe a more playful font would be suitable.</p>
<h1 id="images">Images</h1>
<p>If you are going to use images on your website, try and get these ready beforehand and have them in a folder so you can focus on development when coding. You should always aim to optimize images aswell. Google Lighthouse is a good way of auditing a website to get information on performance and accessibility including image optimization, check out my post on it <a target="_blank" href="https://blog.alanmontgomery.co.uk/using-google-lighthouse-to-audit-any-website">here</a>.</p>
<h1 id="the-layout">The Layout</h1>
<p>You want to have an idea of how your content will be laid out on your individual web pages. Consider thinking about how spaced out your content "containers" will be, if you will have a centred website, or a full-width website, if you'll have a split column website or multiple columns, etc.</p>
<h1 id="sketching">Sketching</h1>
<p>The best way to plan out your layout is to sketch it out.</p>
<p>✏️ Use a pencil (or pen) and paper - draw out exactly what is in your head on a piece of paper, and this could act as your base layout/design for your website. This eliminates the guessing game while developing your website and it will ensure you have a consistent layout.</p>
<h1 id="wireframes">Wireframes</h1>
<p>You could plan your layout a step further with wireframes. What are wireframes? These are like a "digital sketch" of your layout/design done on the computer where you can really solidify your ideas. This step isn't needed though if you successfully sketch out your layout by hand.</p>
<blockquote>
<p>I hope you enjoyed this short post about planning a website. It's SO important.</p>
</blockquote>
<p>I've recently started a YouTube channel for coding tutorials, beginner to advanced, I'd love to see you there;</p>
<p><a target="_blank" href="https://bit.ly/alanmontgomerycoding">Alan Montgomery - Coding Tutorials</a></p>
]]></content:encoded></item><item><title><![CDATA[How to use the useState hook in React]]></title><description><![CDATA[React is a very powerful JavaScript library, I'm sure everyone will agree right? One of the most advantageous aspects of React is the ability to re-render part of your UI based on some state that you hold values in.
I'm going to show you here in a fe...]]></description><link>https://blog.alanmontgomery.co.uk/how-to-use-the-usestate-hook-in-react</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/how-to-use-the-usestate-hook-in-react</guid><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[software development]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Thu, 29 Oct 2020 12:34:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1603974850103/cN1rX0EtD.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>React is a very powerful JavaScript library, I'm sure everyone will agree right? One of the most advantageous aspects of React is the ability to re-render part of your UI based on some state that you hold values in.</p>
<p>I'm going to show you here in a few simple tutorial-like steps how to implement the useState hook into your React app. If you'd prefer to learn via video, I actually have a YouTube video explaining this as well.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=icrrnFSjg8c">https://www.youtube.com/watch?v=icrrnFSjg8c</a></div>
<h1 id="step-1">Step 1</h1>
<p>If you haven't already got a React project up and running you can spin one up quite easily using the npx command:</p>
<pre><code>npx <span class="hljs-keyword">create</span>-react-app my-app
</code></pre><blockquote>
<p>This will create a project called <strong>my-app</strong> inside the directory you're currently in, on your CLI, using the create-react-app utility.</p>
</blockquote>
<p>If you already have a project, you can skip this step.</p>
<h1 id="step-2">Step 2</h1>
<p>Let's create a new page or component for this little example. We'll be creating a functional component for this case, as hooks can only be used within functional components and not class-based components.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;

<span class="hljs-keyword">const</span> MyComponent = <span class="hljs-function">() =&gt;</span> {

    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>My Component<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>
    );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> MyComponent;
</code></pre>
<blockquote>
<p>This is a very simple component which, at the minute only renders a heading tag saying "My Component". However, this is the perfect basis to implement the useState hook and get familiar with it, without much bloated code to distract you.</p>
</blockquote>
<h1 id="step-3">Step 3</h1>
<p>We need to import the useState hook method from react. This is a method which can basically take in a default value and gives you back a variable, and a set method for that variable to override or re-set the value it's holding.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
</code></pre>
<h1 id="step-4">Step 4</h1>
<p>We need to somehow use this hook method now. We can set out a state variable inside our component, anywhere before our return like this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> [ myVariable, setMyVariable ] = useState(<span class="hljs-string">"Hello"</span>);
</code></pre>
<blockquote>
<p>What have we done here?</p>
</blockquote>
<p>We have a variable called <strong>myVariable</strong> which holds an initial or <strong>default</strong> value of "Hello", quite like writing:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> myVariable = <span class="hljs-string">"Hello"</span>;
</code></pre>
<p>We also have a set method now, which we can use to update the value held in our state variable and call it just like we'd call a regular function, like:</p>
<pre><code class="lang-javascript">setMyVariable(<span class="hljs-string">"Goodbye"</span>);
</code></pre>
<p>With our state variable and set method pair set up, we can use our state variable in a number of ways:</p>
<ol>
<li>As a condition, to render a piece of UI in our return</li>
<li>To simply output the value of the state variable</li>
<li>Pass this state variable as a prop into a child component</li>
</ol>
<p>With that being said, let's see how we can achieve these 3 things.</p>
<h3 id="using-our-state-variable-as-a-condition-to-render-a-piece-of-ui-in-our-return">Using our state variable as a condition to render a piece of UI in our return</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">return</span> (
    { myVariable === <span class="hljs-string">"Helllo"</span> ? <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Welcome to My Component!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span> : <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Goodbye, Hope you enjoyed My Component.<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>
);
</code></pre>
<blockquote>
<p>How you write your ternary operators in your JSX, is obviously up to you.</p>
</blockquote>
<h3 id="to-simply-output-the-value-of-the-state-variable">To simply output the value of the state variable</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{ myVariable }, there!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>
);
</code></pre>
<h3 id="pass-this-state-variable-as-a-prop-into-a-child-component">Pass this state variable as a prop into a child component</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">MyChildComponent</span> <span class="hljs-attr">variable</span>=<span class="hljs-string">{</span> <span class="hljs-attr">myVariable</span> } /&gt;</span></span>
);
</code></pre>
<p>Now, what about our set method, how can we use this? Well, it's quite simple, as I said above, we can use this set method (or function) just like any regular javascript function.</p>
<ul>
<li>Let's add a button into our simple React component to demonstrate this.</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;

<span class="hljs-keyword">const</span> MyComponent = <span class="hljs-function">() =&gt;</span> {

    <span class="hljs-keyword">const</span> [ myVariable, setMyVariable ] = useState(<span class="hljs-string">"Hello"</span>);

    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{ MyVariable } friend!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{</span> () =&gt;</span> setMyVariable("Goodbye") }&gt;Set Variable<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> MyComponent;
</code></pre>
<p>This will basically call the setMyVariable function and pass in a value to update the state with, because we are outputting the state variable value in our <strong>h1</strong> tag, and we know that a change in state promotes a UI re-render of affected elements, we now know that the value held within the h1 tags will change to <strong>Goodbye friend</strong>.</p>
<p>I hope this helped you understand the useState hook in React. It really is very simple once you grasp how to use it and what you can do with it.</p>
<p>Again, if you'd prefer the video format i have a <a target="_blank" href="https://www.youtube.com/watch?v=icrrnFSjg8c">YouTube video</a> as well.</p>
<p>Don't forget to head over to my YouTube, I'd love to see you there, where I'm posting coding tutorials, all to do with JavaScript, React and more coming!</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://bit.ly/alanmontgomerycoding">https://bit.ly/alanmontgomerycoding</a></div>
]]></content:encoded></item><item><title><![CDATA[How to be a confident, new web developer]]></title><description><![CDATA[Just DO it.
This may seem really simple, but sometimes just doing it, works. A lot of the time you will hesitate when wanting to try something different in web development. For example, if you have an idea of how to implement functionality, my advice...]]></description><link>https://blog.alanmontgomery.co.uk/how-to-be-a-confident-new-web-developer</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/how-to-be-a-confident-new-web-developer</guid><category><![CDATA[Web Development]]></category><category><![CDATA[Developer]]></category><category><![CDATA[software development]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Thu, 29 Oct 2020 01:02:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1603933334983/ghrvJSKj5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="just-do-it">Just DO it.</h1>
<p>This may seem really simple, but sometimes just doing it, works. A lot of the time you will hesitate when wanting to try something different in web development. For example, if you have an idea of how to implement functionality, my advice is just to do it! Try it out. If it doesn't work, try something else - it's the best way to self learn as well after you have learned the basics and fundamentals.</p>
<h1 id="seek-advice">Seek advice.</h1>
<p>Seeking good experienced advice from a web developer who knows what they are talking about is a great way to solidify and help you understand a problem. If you're stuck on an issue and you really can't understand how to fix or implement it, then sometimes, asking a senior or more experienced web developer will benefit you. They can pass knowledge and expertise on to you which you'll never forget!</p>
<h1 id="take-a-break">Take a break.</h1>
<p>I find a lot of times if I've hit a problem in web development I can't solve, taking a quick 5-minute break and coming back to the code helps massively. You can clear your head in the space of 5 minutes, get a new perspective on things, and get fresh ideas. Most of the time it works and it can work for you too!</p>
<p>These are just some pointers to keep in mind when you are developing and implementing new ideas/solutions after you've learnt the fundamentals and basics.</p>
<p>Ps. I've recently started a YouTube channel for coding tutorials, would love to see you over there.
<a target="_blank" href="https://bit.ly/alanmontgomerycoding">Alan Montgomery - Coding Tutorials</a></p>
]]></content:encoded></item><item><title><![CDATA[Using Google Lighthouse to audit any website]]></title><description><![CDATA[👉 First of all, what is Google Lighthouse?
It's an automated audit tool aimed at helping you improve web page quality. They provide reports for:
✔️ Performance
✔️ Accessibility
✔️ Best Practices
✔️ Progressive Web App Capabilities
✔️ SEO
👉 Why is t...]]></description><link>https://blog.alanmontgomery.co.uk/using-google-lighthouse-to-audit-any-website</link><guid isPermaLink="true">https://blog.alanmontgomery.co.uk/using-google-lighthouse-to-audit-any-website</guid><category><![CDATA[SEO]]></category><category><![CDATA[Google Chrome]]></category><category><![CDATA[Developer Tools]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Alan Montgomery]]></dc:creator><pubDate>Wed, 28 Oct 2020 09:00:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1603876019354/l-qtjQlEh.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="first-of-all-what-is-google-lighthouse">👉 First of all, what is Google Lighthouse?</h2>
<p>It's an automated audit tool aimed at helping you improve web page quality. They provide reports for:</p>
<p>✔️ Performance
✔️ Accessibility
✔️ Best Practices
✔️ Progressive Web App Capabilities
✔️ SEO</p>
<h2 id="why-is-this-useful">👉 Why is this useful?</h2>
<p>With any website or web page, it's very important to provide the fastest, highest performing content to the browser as possible. Why? So your site has speed, doesn't lag and doesn't force users to leave your site instantly. It also greatly helps with SEO (Search Engine Optimization).</p>
<h2 id="the-google-lighthouse-tool">👉 The Google Lighthouse tool</h2>
<p>There is a free tool as a developer we can use called Lighthouse. This lets us audit any website, in those categories outlined above from 0-100 score - it also gives us really in depth explanations as to what is bringing the score down and how to fix each individual issue encountered.</p>
<h2 id="try-it-out">🔥 Try it out</h2>
<ul>
<li>Go to any webpage using Goggle Chrome</li>
<li>Right click the page and press Inspect</li>
<li>On the console tabs, scroll across to Lighthouse</li>
<li>Click generate report
<a target="_blank" href="https://developers.google.com/web/tools/lighthouse">https://developers.google.com/web/tools/lighthouse</a></li>
</ul>
<p>This is an absolute must use tool if you want to provide top quality, fastest performing webpages that are going to rank high in searches with SEO.</p>
<p>This image is an audit that I've just done on dev community I am building.</p>
<p><img src="https://i.imgur.com/5GRLDlu.jpg" alt="Google Lighthouse audit" /></p>
]]></content:encoded></item></channel></rss>