<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kaitlyn Greve on Medium]]></title>
        <description><![CDATA[Stories by Kaitlyn Greve on Medium]]></description>
        <link>https://medium.com/@kgreve14?source=rss-f79c6d093535------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EBoN-KHAM3V5uqrhH6KLQQ.jpeg</url>
            <title>Stories by Kaitlyn Greve on Medium</title>
            <link>https://medium.com/@kgreve14?source=rss-f79c6d093535------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 13:11:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kgreve14/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Budgeting Allows My $7 Latte]]></title>
            <link>https://medium.com/@kgreve14/how-budgeting-allows-my-7-latte-37a08cc774e6?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/37a08cc774e6</guid>
            <category><![CDATA[best-budgeting-app]]></category>
            <category><![CDATA[how-to-budget]]></category>
            <category><![CDATA[personal-budgeting-app]]></category>
            <category><![CDATA[budgeting-tips]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Fri, 03 Jan 2025 23:03:02 GMT</pubDate>
            <atom:updated>2025-01-03T23:03:02.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sf913CyjZKq4jt_IeW-nQQ.png" /></figure><p>I recently came across a post from a budgeting app that said something like, ‘Buying your coffee today is funding someone else’s house for tomorrow’. My gut reaction? “Well that feels outdated”.</p><p>Here’s the reality: skipping your $7 latte isn’t going to fund a new home in a year. Plus, you’d miss out on the little joy that latte brings. Budgeting should be about working toward your bigger goals while still leaving room for the things you love.</p><p>What does it look like to cover essentials like rent and groceries, save for healthcare and emergencies, <em>and</em> still have space for things like lattes? I’m going to break it down super simply using zero-based budgeting as my guide (don’t worry, I’ll explain if you’re new to the concept).</p><p>Of course, everyone’s financial situation is different, and I’m not a financial expert — just a passionate budgeter sharing my perspective. My goal is to challenge the outdated idea that ‘a latte will ruin you financially’ and encourage a more balanced approach to budgeting.</p><p>Now that we’ve got that out of the way, grab your favorite latte — no guilt required — and let’s dive in.</p><p><strong>Zero-Based Budgeting:<br></strong>Unlike traditional budgeting where spending limits are just targets, zero-based budgeting uses your actual available money to set those limits.</p><p>If you spend more in one category, you’ll need to account for that overspend from another, because you’re working with real dollars, not theoretical limits. It’s about confidently managing the money you have <em>right now</em>.</p><p>With this method, let’s move on to setting up your budget.</p><ol><li><strong>Know your Income— <br></strong>Be clear about how much money you bring in each month. This is the starting point for everything — your needs, wants, and goals. Knowing this number helps you divvy it up wisely.</li><li><strong>Know your Expenses— </strong><br>List every expense — rent, groceries, transportation, health, and emergencies. Don’t forget the fun stuff — eating out, coffee, hobbies. This isn’t the time to pretend you don’t spend on extras. 😉 The goal is to see where your money’s going so you can make mindful decisions in the next step.</li><li><strong>Prioritize your Spending— </strong><br>Sort your spending from ‘most important’ to ‘least important’ and allocate your income accordingly. Maybe you cut back on coffee to save for something bigger — or maybe you don’t, because that latte brings you joy and there’s nothing extra you’re saving for right now. It’s all about balance, and the choices you make should reflect your goals.</li><li><strong>Track your Spending— </strong><br>Keep an eye on your money. Use whatever system works best for you (I’m partial to <a href="https://rangerbudget.com/">Ranger</a>, of course). The goal is to track your transactions and see where your money’s going. That way, you’ll know exactly what’s left each week or month. Before grabbing that latte, give your budget a quick check — if it’s in there, enjoy it guilt-free!</li></ol><p>The beauty of budgeting: making room for the things you want, while still taking care of the things you need. If that means a weekly latte, go for it — just make sure it’s part of a bigger plan that helps you stay on track with your goals. Remember, budgeting is a tool, not a rule. It’s all about balance and understanding where your money’s going, so you can spend with confidence. You’ve got this.</p><p>And hey, if you’re ever unsure or want help, feel free to reach out to me via email (kaitie@rangerbudget.com) or <a href="https://x.com/kgreve14">X (formerly known as Twitter 😉)</a>.</p><p>Happy budgeting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37a08cc774e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Zero Based Budgeting — Simple & Beautiful]]></title>
            <link>https://medium.com/@kgreve14/zero-based-budgeting-simple-beautiful-2424e419e2d8?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/2424e419e2d8</guid>
            <category><![CDATA[budgeting]]></category>
            <category><![CDATA[personal-budgeting-app]]></category>
            <category><![CDATA[indie-developer]]></category>
            <category><![CDATA[zero-based-budgeting]]></category>
            <category><![CDATA[personal-finance]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 21:01:17 GMT</pubDate>
            <atom:updated>2024-12-06T21:01:17.847Z</atom:updated>
            <content:encoded><![CDATA[<h3>Zero Based Budgeting — Simple &amp; Beautiful</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2eUVg2yTWZsWP-F6KMsq_g.jpeg" /><figcaption>Ranger Hero</figcaption></figure><p>In 2023, our small team — a husband, wife, and best friend — set out on a mission to empower people to have a healthy relationship with their finances, free from fear-based decision-making.</p><p>Of all the budgeting apps we’ve tried, none struck the right balance of being simple to use, realistic, and friendly. So, we built <a href="https://rangerbudget.com/">Ranger</a> — a tool not only for ourselves but also for all the friends and family we’ve seen struggle with finances over the years.</p><p><em>🎬 Want to watch a demo or see more? Head over to </em><a href="https://rangerbudget.com/"><em>Ranger</em></a><em> to check it out!</em></p><p>We want budgeting to be less scary — here’s how we’re doing it.</p><p><strong>💸 Zero Based Budgeting <br></strong>Ranger works with your actual balance, not theoretical limits. If you spend more in one area, you adjust elsewhere. It’s about confidently managing the money you have right now.</p><p><strong>✨ Enriched Info (BETA) </strong><br>No more mystery charges. Ranger turns “AMZN 14231” from your bank statement into actual, real-world product names.</p><p><strong>💪 Built for Real People </strong><br>We’re not backed by big investors or trying to take over the world — we’re just three people who wanted to make budgeting feel less scary. <a href="https://rangerbudget.com/">Try it free for 35 days</a>, then join our community for $7/month or $50/year. ✌️</p><p><strong>🔒 Secure by Default </strong><br>We partner with Plaid to securely connect your financial accounts. Everything is encrypted, and we never store login credentials.</p><p><strong>⚡️ Sync Everything </strong><br>Manage all your accounts in one place, even if you have a dozen credit cards across multiple banks.</p><p><strong>🪴 Flexible Categories </strong><br>No rigid systems or preset categories here. Create a plan that fits your life and organize your money in a way that makes sense to you.</p><p>The features we’ve built into Ranger are deeply rooted in our own experiences with budgeting. On a personal note, I didn’t start budgeting until my then-fiancé (now husband) introduced me to the concept. I oscillated between two extremes: either not caring and overspending or avoiding purchases I had saved for because I was afraid to part with my money. Neither of these mindsets exemplified fearless budgeting. This personal struggle is what fuels my love for Ranger and its simple, yet impactful, approach to budgeting. It’s the tool I wish I had when I first started budgeting.</p><p>At Ranger, we’re passionate about helping you cultivate a positive, empowered relationship with your finances. Ready to get started? Try a free 35-day trial of <a href="https://rangerbudget.com/">Ranger</a> today and see how simple and beautiful budgeting can be.</p><p>Have questions, feedback, or just want to chat? You can reach out to me on Twitter — <a href="https://x.com/kgreve14">@kgreve14</a> — or email me at <a href="/service/mailto:kaitie@rangerbudget.com">kaitie@rangerbudget.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2424e419e2d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ranger, A Budgeting App]]></title>
            <link>https://medium.com/@kgreve14/ranger-a-budgeting-app-f91de4242ccc?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/f91de4242ccc</guid>
            <category><![CDATA[budgeting]]></category>
            <category><![CDATA[budgeting-app]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Fri, 06 Oct 2023 02:15:15 GMT</pubDate>
            <atom:updated>2023-10-06T02:15:15.354Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gEH7FHxHU5l7uI7VSbDllg.jpeg" /></figure><p>🐕 Meet Ranger, my Australian Shepherd. He’s an outstanding companion. Ranger cares deeply for his herd. This dog can read a room. His greatest joy, just before sprinting after a tennis ball, is ensuring you feel secure and nurtured.</p><p>That’s what Ranger, a budgeting app, set out to accomplish. A budgeting app is not a revolutionary idea at this point, but the way Ranger is doing it, is. Ranger was built with the idea of guiding users to view their finances in a healthy and realistic way, free from fear-based decision-making.</p><p><em>For the remainder of this article, Ranger will refer to the budgeting app.</em></p><p>🚀 Ranger empowers you to take control of your finances by letting you create and customize your budget categories based on your priorities. There is no forcing you into predefined, permanent categories. Ranger offers the flexibility to customize your budget, whether you have unique expenses or specific spending priorities.</p><p>🧮 Every calculation and amount in Ranger<strong> </strong>has been deeply cared for and thought out. Every amount in the app is transparent. This transparency ensures that you have a realistic and up-to-date understanding of your finances, eliminating the uncertainty that can plague other budgeting apps with unclear numbers.</p><p>✨ Ranger’s transaction enrichment feature removes the guesswork from your spending by offering detailed and easily understandable information. For instance, instead of a vague reference, i.e. “AMZN#4759”, you’ll see “Atomic Habits by James Clear, Amazon, $15.99,” allowing you to quickly identify your transactions without the need for detective work.</p><p>💸 Our primary aim with Ranger is to help you build and maintain a healthy, fear-free relationship with your finances. We believe that financial stability and peace of mind are the foundations of a successful financial journey. Ranger is here to shepherd you in achieving these goals.</p><p>The Ranger team is incredibly excited to be sharing this new budgeting app. Ranger is currently in beta testing — and looking for interested participants! Reach out to me via my <a href="https://www.linkedin.com/in/kaitlyn-greve/">LinkedIn</a>, message me here on Medium, or, follow this <a href="https://rangerbudget.com/">link</a> to get started.</p><p>😄 Happy budgeting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f91de4242ccc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Notable ✏️ —Implementing Firebase]]></title>
            <link>https://towardsdev.com/building-notable-%EF%B8%8F-implementing-firebase-f82d1a66d4d6?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/f82d1a66d4d6</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Thu, 16 Feb 2023 17:38:21 GMT</pubDate>
            <atom:updated>2023-02-17T12:33:57.737Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u8Y8dfhDEV7VjedxdsyoWA.png" /><figcaption>Screen shot of the Notable login page</figcaption></figure><p>Built with a React frontend and Firebase backend, Notable is a full CRUD, authenticated notes app. When a user logs in, they are welcomed by a personalized message and the current date. As notes are added, they are saved with a timestamp which sorts by newest to oldest. Each entry can be re-visited, updated, and deleted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YF7T0-T1q9e4lJyxT03l5A.png" /><figcaption>Screen shot of Notable upon login</figcaption></figure><p>Several aspects of building Notable deepened my skills and knowledge of React — such as React hooks, passing props, and creating reusable components. Utilizing Firebase, though, was completely new.</p><p>This post is going to focus primarily on learning and implementing the Firebase Firestore and Firebase Authentication, via Google. I will also spend some time on some of my favorite aspects of Notable.</p><h3>Learning Firebase</h3><p>If you have not used Firebase before, let me introduce you to the world of Back-end as a service (BaaS). Of course, Firebase can do a lot of things. While reading a fantastic article exploring Firebase for all it’s ins and outs, <a href="https://medium.com/firebase-developers/what-is-firebase-the-complete-story-abridged-bcc730c5f2c0">linked here</a>, the writer says —</p><p>“Firebase is Firebase.”</p><p>Fair enough. Firebase is a toolset, that allows developers to focus more on user / app experience. This includes authentication, databases, analytics, and more. So, Firebase could be briefly summarized as an app development platform for building, improving, and growing apps.</p><h4>Setting Up the Firebase Config File</h4><p>Setting up the config folder is a crucial first step when implementing Firebase into a project. While navigating through Firebase — ‘Start a new Project’ — I was given a personal firebaseConfig object. This object is personal to me and my project. The firebaseConfig object will live in the src folder in a file called firebase-config. I accessed different variables declared in this file to make my<strong> G</strong>et, <strong>P</strong>ost,<strong> P</strong>atch, and <strong>D</strong>elete requests in my React components, as well as implement my login and sign out functionality.</p><p>After importing everything I needed for building Notable, my firebase-config file looked like this —</p><pre>import { initializeApp } from &quot;firebase/app&quot;;<br>import { getFirestore } from &quot;@firebase/firestore&quot;;<br>import { getAuth } from &quot;firebase/auth&quot;;<br><br>const firebaseConfig = {<br>    apiKey: &quot;my-apiKey&quot;,<br>    authDomain: &quot;my-authDomain&quot;,<br>    projectId: &quot;my-projectId&quot;,<br>    storageBucket: &quot;...&quot;,<br>    messagingSenderId: &quot;...&quot;,<br>    appId: &quot;...&quot;,<br>    measurementId: &quot;...&quot;<br>};<br>// this object is unique to ME &amp; MY project<br><br>const app = initializeApp(firebaseConfig);<br><br>export const auth = getAuth(app);<br>export const db = getFirestore(app);</pre><p>It was incredibly simple to connect my Firebase project with my React app. It was a true ‘step-by-step’ led implementation. From here I was able to use the variables declared in firebase-config file and other built in ‘methods’ from Firebase to query my database and use the data entries.</p><p>I knew when I started building Notable that associating each note entry with a specific user was vital. Also, Notable is a personal note taking app, so it was important to me to implement login functionality to securely store a user’s entires. This would mean setting up authentication to capture the user id (implemented in code using uid) and building out auth.</p><h4>Google Authentication with Firestore</h4><p>Firebase Authentication offers a range of backend services, simple SDKs (<strong>S</strong>oftware <strong>D</strong>evelopment <strong>K</strong>it), and pre-built UI libraries that facilitate user authentication for your application. This service supports authentication through various methods, including passwords, phone numbers, and popular federated identity providers such as Google, Facebook, and Twitter.</p><p>This is not my first time building out auth functionality, and I admit I was wary of the process. I first built and implemented auth with Ruby on Rails. Though I learned a lot in the process of building authentication from scratch, I ran into multiple issues along the way. Using Firebase Authentication was shockingly effortless, especially compared to building it from nothing.</p><p>Personally, I love the ease of logging in with Google, so I was intrigued to learn how to implement that in Notable. Obviously, if a user can login, they should also be able to logout. So, I began with creating two components — Login.js and Signout.js. In the Login component there were only a few things to import.</p><pre>import { auth } from &quot;./firebase-config&quot;<br>import { signInWithPopup, GoogleAuthProvider } from &quot;firebase/auth&quot;;</pre><p>If you can remember, my auth is being imported from ./firebase-config, which is the variable getAuth(app) — app being initializeApp(firebaseConfig). The SignInWithPopup and GoogleAuthProvider are both from Firebase. They are built in methods that I am able to implement and use with ease. What comes next felt way too easy.</p><p>In the Login component I created a function to handle the login functionality. From there, within the return of the Login component, I added a button tag, labeled “Login”, with an onClick. In the onClick was the function I wrote to handle the login functionality. So, when the user clicked “Login”, the function, which I called signInWithGooge(), would be triggered.</p><p>The final Login component looked like this —</p><pre>import { auth } from &quot;./firebase-config&quot;<br>import { signInWithPopup, GoogleAuthProvider } from &quot;firebase/auth&quot;;<br><br>function Login() {<br>    // function to handle login functionality <br>    const signInWithGoogle = () =&gt; {<br>        const provider = new GoogleAuthProvider();<br>        signInWithPopup(auth, provider);<br>    };<br><br>    return (<br>        &lt;div&gt;<br>           &lt;h1&gt;✏️ Welcome to Notable&lt;/h1&gt;<br>           &lt;h3&gt;To login, sign in with Google&lt;/h3&gt;<br><br>           // here is the button that when clicked triggers the <br>           // signInWithGoogle function   <br>           &lt;button onClick={signInWithGoogle}&gt;Sign In&lt;/button&gt;<br>        &lt;/div&gt;<br>    )<br>}<br><br>export default Login;</pre><p>Sign out was just as simple, if not more so. In the Signout component all that had to be imported was auth. After that, the steps are nearly verbatim as in Login. I wrote a function, called signUserOut(), that handled the sign out functionality. From there it was creating a button with an onClick that triggered signUserOut() when clicked. So, the final Signout component looked like this —</p><pre>import { auth } from &quot;./firebase-config&quot;<br><br>function Signout() {<br><br>    const signUserOut = () =&gt; {<br>        auth.signOut()<br>    }<br><br>    return (<br>        &lt;div&gt;<br>            &lt;button onClick={signUserOut}&gt;Sign Out&lt;/button&gt;<br>        &lt;/div&gt;<br>    )<br>}<br><br>export default Signout;</pre><p>The signOut() method we see is a built in with Firebase. It does what it says — signs the current user out.</p><p>Now, Notable has full auth functionality. Users can login with Google and sign out — neither of which were particularly difficult to implement after some exploring the Firebase Auth package documentation. With having auth, Notable could now show user specific data, and allow for a better user experience, via user conditional rendering. Importantly, too, it gives the user a sense of security, knowing their notes are specific to them.</p><p>One would expect that a notes app is connected to a database that stores each note entry. It was incredibly important to ensure data persistence on the frontend and backend, and only rendering data unique to a specific user.</p><h4>The Cloud Firestore</h4><p>Firebase Firestore is a fully managed NoSQL document database. Fully managed, meaning the host is responsible for maintaining routine operating system updates, additional software updates, and other server-level management and configuration tasks. It allows developers to store, sync, and query data for their applications. It is a cloud-based database provided by Google Cloud as part of the Firebase platform, and is designed to be scalable, flexible, and secure. Firestore stores data in documents that contain fields mapped to values, and these documents are organized into collections.</p><p>If you remember, in my firebase-config file, I imported the Cloud Firestore and created a variable called db which I initialized as getFirestore(app). If you need a refresher, I added it here so you don’t have to scroll al the way up —</p><pre>import { getFirestore } from &quot;@firebase/firestore&quot;;<br><br>// &amp;<br><br>export const db = getFirestore(app);</pre><p>Before being able to write functionality for creating, updating, and deleting a new note, I had to get the data first. I decided to house this function in the App.js component — it worked best with my component hierarchy. There were a few steps to getting my data in a state where I could connect it with a user, and use it for the <strong>P</strong>ost, <strong>P</strong>atch, and<strong> D</strong>elete requests.</p><p>Starting with importing all the variables and Firebase methods. I imported from three places:</p><ol><li>firebase-config file</li><li>firebase/firestore</li><li>&amp; react-firebase-hooks/auth</li></ol><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>import { db, auth } from &#39;./firebase-config&#39;<br>import { collection, getDocs } from &#39;firebase/firestore&#39;<br>import { useAuthState } from &quot;react-firebase-hooks/auth&quot;;</pre><p>From the firebase/firestore I imported collection and getDocs. The collection is my ‘collection’ of data. It is all of the documents in my Cloud Firestore. The getDocs is a built in Firestore method that gathered my documents so that I was able to render them on the frontend. Lastly, useAuthState is convenience listener for Firebase Auth’s auth state. I used this to listen for when a user changes. And, since I also used the state and useEffect hook, those had to be imported as well.</p><p>Next came setting up a few key variables and state. I created a state and state setter, called entries and setEntries and initialized them as an empty array — since that is what all new users will begin with, zero entries. Then I set the useAuthState hook to a variable as well, called user.</p><pre>  const [entries, setEntries] = useState([]);<br>  const [user] = useAuthState(auth);</pre><p>Lastly, I created an incredibly important variable, called entriesRef — since each time I am used this variable, I referenced my entries collection. I initialized entriesRef using a ternary operator, since I did not want a non-logged in user to view anything other than the login screen. But, as soon as a user was detected, I could show the entries unique to that logged in user.</p><pre>const entriesRef = user ? collection(db, user.uid) : &lt;Login /&gt;;</pre><p>Basically this line of code, in plain english, says “Is there a user? If there is, show the collection of data associated with that user, otherwise show the login screen.” Then I was free to use the entriesRef, entries &amp;&amp; setEntries state, and user variables to get my data and render it on the frontend.</p><p>Within a useEffect I wrote a function, called getEntries, that would get my data from my Firestore collection, using the Firebase built in method getDocs, and set my entries state to be that data. I made sure to assign this data with an id and key — both of which I assigned data.id, as Firestore assigns a random id for each key value pair. Still within the useEffect, I called getEntries(). The actual code is right below —</p><pre>  useEffect(() =&gt; {<br>    const getEntries = async () =&gt; {<br>      const data = await getDocs(entriesRef);<br><br>      setEntries(data.docs.map((doc) =&gt; <br>          ({ ...doc.data(), id: doc.id, key: doc.id })));<br>    }<br>    getEntries();<br>  }, [user]);</pre><p>In the useEffect dependency array — the second argument of a useEffect call that specifies when the useEffect needs to rerun — I put user. I wanted this useEffect to run each time the user changed, ensuring I would only be displaying the data (notes) that belonged to the logged in user.</p><p>At this point in my code, I had all of the data I needed to render on the frontend, and allow my users to create, revisit, update, and delete all their note entires — while the backend worked to keep up with all those changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OqfHojHUjiLJotv0R99Lzw.png" /><figcaption>Screen shot of note being revisited</figcaption></figure><h4>Firebase Wrapped Up</h4><p>Firebase is an incredible tool to learn and use. In addition to using the Cloud Firestore and Google Authentication, I deployed Notable via Firebase. Plus, Firebase has phenomenal <a href="https://firebase.google.com/docs">documentation</a> to help you with your next project.</p><h3>Conditional Rendering &amp; Design</h3><p>In addition to learning a completely new concept — (Firebase, a BaaS) — I spent lots of time learning how to execute a neat and easy to navigate frontend. So, before I call this article ‘done’ I wanted to highlight some bits of Notable I am particularly proud of.</p><p>First, the design of Notable. I knew, from the beginning, I wanted to design a single page app that flowed with ease — highlighting the fact that its primary function is note taking/keeping. Touches like using the users display name and current date on the home page felt like the perfect bit of personalization. The goal was to have Notable feel like it’s YOUR notes app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7UdgxU6GtuAq46yzm3g-KA.png" /><figcaption>Screen shot of user’s display name &amp; date</figcaption></figure><p>To display the name of the user was fairly simple. When a user logs in to Notable with Google there is a user object available for use. After I console.log(user) I was able to see the different attributes / key value pairs available to me. The key value pair that made most sense was displayName. The code for my header looks like this —</p><pre>&lt;h1 className=&#39;header&#39;&gt;👋 Hello, {user.displayName}.&lt;/h1&gt;</pre><p>To get the current date was fairly straightforward, however, I also wanted to sort each entry from newest to oldest. To do that, though, I needed to use a Unix Timestamp. Instead of creating two completely different variables for the current date and timestamp — I wrote something a little more dynamic.</p><p>I started with creating a variable called timestamp which was initialized as Date.now(). This gave me a Unix Timestamp in milliseconds. In order to sort entries I created another variable called sortedEntries, and on my entries array I used .slice() which creates copy of the original entries array, ensuring the original array remains unmodified. Next I used .sort((a, b) =&gt; b.timestamp — a.timestamp) — which sorts the copied entries array in descending order based on the timestamp property of the elements. When I render each note entry on the frontend, I am using the sortedEntries array.</p><p>To display the current date in the header I made another variable called current and initialized it to new Date(timestamp). Here, we are getting a date object with our current, already initialized, timestamp. Creating the date format is a matter of using string interpolation.</p><pre>// In the App.js component<br>let current = new Date(timestamp); <br>const todayDate = <br>  `${current.getMonth() + 1}/${current.getDate()}/${current.getFullYear()}`;<br><br>// In the Header.js component - to display the current date<br>&lt;h3 className=&#39;currentDate&#39;&gt;🗓 Today&#39;s date is {todayDate}&lt;/h3&gt;</pre><p>Something else I valued was adding some conditional rendering for a few aspects —</p><ol><li>A note welcoming a new user — that would change once their entires [] was no longer empty</li><li>Error Message — notifying the user their entry was not saved, as well as why it was not</li><li>Success Message — celebrating with the user that their entry was successfully added to their saved notes</li></ol><p>For the ‘welcome’ note, I added a ternary operator surrounding the &lt;textarea /&gt; tag in my NewEntry component, within the return &lt;form /&gt;. My entries data is an array of all the entries associated with the logged in user. My operator checked if entries.length === 0. If that statement is true, then populate the placeholder text in the &lt;textarea /&gt; tag with a welcome message, otherwise have it simply say “Entry…✏️”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*o4Bu5GU5AoJTco9fh1vdQA.png" /><figcaption>Screen shot showing placeholder text with no previous entries</figcaption></figure><p>vs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*TvHTX9b0O9p5ZojVI1nxpg.png" /><figcaption>Screen shot showing placeholder text with entries</figcaption></figure><p>For me, small touches like this are important for creating a great user experience.</p><p>The error / success handling in Notable deserve a blog post for themselves, but I will briefly cover the error message here to display another case of conditional rendering.</p><p>In an effort to keep a user from submitting a note without a title and content, I set up some basic state and initialized the error: false &amp;&amp; msg: &#39;&#39;.</p><pre>const [errorMessage, setErrorMessage] = useState({ error: false, msg: &quot;&quot; });</pre><p>Within a function called addEntry, which was connected to the submit button on my form, I set up an ‘if’ statement that said “if either the newTitle or newContent state values remain an empty string, set the error message to be true, and the message to be whatever is in the string”. So, when a user attempts to submit an empty entry, they see this rendered on the frontend —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lFDz86X2MG-0MrRBSXIEpA.png" /><figcaption>Screen shot of error message — after clicking ‘add note’</figcaption></figure><p>The error message will not go away until a successful entry goes through — meaning the newTitle and newContent values cannot be an empty string. At which point you see a success message like this one —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buPZHcA9d_Ytng_5ZzOwyg.png" /><figcaption>Screen shot of success message</figcaption></figure><p>The success message was set up fairly similarly — but with a few added features, which is why it will probably receive a post of its own.</p><p>If visualizing it in code is helpful, I have left that here.</p><pre>// error message state and setter<br>const [errorMessage, setErrorMessage] = useState({ error: false, msg: &quot;&quot; });<br><br>// in the addEntry() function <br>if (newTitle === &quot;&quot; || newContent === &quot;&quot;) {<br>      setErrorMessage({<br>          error: true,<br>            msg: &quot;Hey there! Make sure all form fields have been filled out <br>                  before submitting.&quot;<br>      });<br><br>// in the return, under the form <br>{errorMessage?.msg &amp;&amp; (&lt;div&gt;{errorMessage.msg}&lt;/div&gt;)}</pre><h3>Thank You!</h3><p>If you have made it this far, thank you for taking the time to read this post. Building Notable was a huge learning process for me, and I sincerely enjoyed spending the time I did building this single page notes app.</p><p>Feel free to reach out if you have any questions or feedback for either this post or Notable itself.</p><p>Definitely feel free to visit the Github repo here — <a href="https://github.com/kaitlyngreve/journal-app">Github</a></p><p>— OR —</p><p>Visit the deployed site here — <a href="https://journal-app-42603.web.app/">Notable</a></p><h4>Happy coding 🥳</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f82d1a66d4d6" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/building-notable-%EF%B8%8F-implementing-firebase-f82d1a66d4d6">Building Notable ✏️ —Implementing Firebase</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Christmas Drag & Drop — With React DnD]]></title>
            <link>https://towardsdev.com/a-christmas-drag-drop-with-react-dnd-39d34e358c4?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/39d34e358c4</guid>
            <category><![CDATA[react-dnd]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Thu, 15 Dec 2022 17:09:18 GMT</pubDate>
            <atom:updated>2022-12-16T14:20:35.788Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Christmas Drag &amp; Drop — With React DnD</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*obt_1ARX_nkvSTQk611-IA.jpeg" /></figure><p>Drag and drop is a super fun feature to implement into your next app or project. While there are several ways to implement drag and drop, this article is focusing on how to implement with <a href="https://react-dnd.github.io/react-dnd/about">React Dnd</a> (<em>follow this link for React Dnd Documentation</em>). Built on Redux, React DnD wraps your components and inserts props — instead of using readymade widgets.</p><p>In this post we will follow along with a mini drag and drop project I built, where you drag presents under a Christmas tree. Tis the season, right? If after reading you want to visit my GitHub repo, as well as the deployed app, I have linked them at the end.</p><h4>How Does It Work?</h4><p>After implementing drag and drop into your project, you will be able to transfer data throughout your application, updating both the state of the application and appearance in response to the drag and drop events.</p><p>What does that mean, though? When you drag an item from point A and drop it at point B, both the actual appearance and the React state are updated. Updating the state means that once we drop it at point B, it won’t immediately go back to point A. It is worth noting — unless you set up your state to persist, it will revert back on a page refresh.</p><p>Right now, we are focusing purely on implementation. So, let’s get to it!</p><h4>Installing React DnD</h4><p>Before we can even begin implementation, once you create your react app, we need to install React DnD. In your terminal, use the following command —</p><pre>npm install react-dnd react-dnd-html5-backend</pre><p>The react-dnd-html5-backend is what will allow React DnD access to the HTML5 drag and drop API under the hood. Thankfully, we won’t have to run into the possible browser bugs with HTML5 drag and drop — because React DnD takes care of them for us, internally.</p><p>Now that you have React DnD installed, we can head to setting up our components.</p><h4>Setting Up</h4><p>In your App component, import the DndProvider component. This component is what *provides* our app with drag and drop capabilities.</p><p>You will also need to import our HTML5Backend. This will be the prop we insert into our DndProvider component.</p><pre>import { DndProvider } from &quot;react-dnd&quot;;<br>import { HTML5Backend } from &quot;react-dnd-html5-backend&quot;;</pre><p>Now we can set up the rest of our App component. It is going to look something like this —</p><pre>import React from &quot;react&quot;;<br><br>function App() {<br>  return (<br>    &lt;DndProvider backend={HTML5Backend}&gt;<br>        // The Drag and Drop Application<br>    &lt;/DndProvider&gt;<br>  );<br>}<br><br>export default App;</pre><p>If you have ever used ReactRouter, you remember wrapping everything with the Router component? It is a similar case for React DnD. Now, each component we build and set between the DndProvider component is capable drag and drop power!</p><h4>Building Our Components</h4><p>First, create a new component. I called mine DragDrop.js. This component is where most of our drag and drop logic is going to be held. The component should look like this —</p><pre>import React from &quot;react&quot;;<br><br>function DragDrop() {<br>  return;<br>}<br><br>export default DragDrop;</pre><p>Back in our App.js component, we can insert our DragDrop component. Make sure to import it at the top!</p><pre>import React from &quot;react&quot;;<br>import DragDrop from &#39;./DragDrop&#39;;<br><br>function App() {<br>  return (<br>    &lt;DndProvider backend={HTML5Backend}&gt;<br>        &lt;DragDrop /&gt;  <br>    &lt;/DndProvider&gt;<br>  );<br>}<br><br>export default App;</pre><p>Our next step is going to be setting up a variable that hold our photos we want to use as the draggable items. We will do this in the DragDrop component.</p><p>To do this, we will create an array of objects. Like so —</p><p><em>use any photo url here …</em></p><pre>const GiftPictures = [<br>    {<br>        id: 1,<br>        url:<br>          &quot;url&quot;<br>    },<br>    {<br>        id: 2,<br>        url:<br>            &quot;url&quot;<br>    },<br>    {<br>        id: 3,<br>        url:<br>            &quot;url&quot;    <br>    }<br>];</pre><p>Next, we are going to create a component just for our GiftPictures. This component is where we are going to set up our images as draggable items.</p><p>Create a new component file. I called mine GiftPicture. Once it is set up, which I have demonstrated below, we are going to import it into our DragDrop component.</p><pre>import React from &quot;react&quot;;<br><br>function GiftPicture() {<br>  return;<br>}<br><br>export default GiftPicture;</pre><p>In order to access each individual gift picture, we will need to map through our array and pass the url and id to our GiftPicture component as props.</p><p>Back in our DragDrop component, we can do this map in our return. Here is what this component looks like so far —</p><pre>import React from &quot;react&quot;;<br>import GiftPicture from &#39;./GiftPicture&#39;;<br><br>const GiftPictures = [<br>    {<br>        id: 1,<br>        url:<br>          &quot;url&quot;<br>    },<br>    {<br>        id: 2,<br>        url:<br>            &quot;url&quot;<br>    },<br>    {<br>        id: 3,<br>        url:<br>            &quot;url&quot;    <br>    }<br>];<br><br>function DragDrop() {<br>  return(<br>    &lt;div className=&#39;Gifts&#39;&gt;<br>      {GiftPictures.map((giftPicture) =&gt; {<br>        return &lt;GiftPicture url={giftPicture.url} id={giftPicture.id} /&gt;;<br>      })}<br>    &lt;/div&gt;<br>}<br><br>export default DragDrop;</pre><p>Let’s make sure we know what is going on here.</p><p>Step 1: Import our GiftPicture component at the top of the DragDrop component</p><p>Step 2: We <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map">map</a> through our GiftPictures array. Each item in our array is a giftPicture with two keys &amp; values — a url and id.</p><p>Step 3: Return our GiftPicture component, and pass in our props.</p><p>Now we have access to each individual object in our array. In the GiftPicture component, we are now going to display our images in our app! Here is what they would look like —</p><pre>import React from &quot;react&quot;;<br><br>function GiftPicture({ url, id }) {<br>  return(<br>    &lt;div&gt;<br>      &lt;img<br>         src={url}<br>       /&gt;<br>    &lt;/div&gt;<br>  )<br>}<br><br>export default GiftPicture;</pre><p>Remember how in our map and return in the DragDrop component we passed in the url and id? That is what we are passing in here ^ as props!</p><p>Here is a reminder of the code that allows us to do this —</p><pre>// in the DragDrop component - within the map<br>return &lt;GiftPicture url={giftPicture.url} id={giftPicture.id} /&gt;;</pre><p>We pass in the id because each mapped item requires a unique key. The url is going to be used as our img src.</p><p>Now, your images will be displayed in your app.</p><h4>Recap So Far …</h4><p>That was a lot of component building and going back and forth between them! So far we have three components. Our App, DragDrop, and GiftPicture components are each taking care of its own logic. Up in App , we have our DragDrop component wrapped in the DndProvider component, which gives DragDrop its drag and drop capabilities. In DragDrop we have our GiftPictures array, which we map through and pass key value pairs as props to our GiftPicture component. In the GiftPicture component, accepting the url and id props, and using the url as our src in our img tag.</p><p>This set up is important to the actual implementation of our drag and drop feature. I would recommend being comfortable with where we are so far!</p><h4>Implementing Drag and Drop</h4><p>Now, with everything is set up correctly, we can start building our drag and drop features! First, we will make our images draggable items. Let’s take a look at our GiftPicture component so far.</p><pre>import React from &quot;react&quot;;<br><br>function GiftPicture({ url, id }) {<br>  return(<br>    &lt;div&gt;<br>      &lt;img<br>         src={url}<br>       /&gt;<br>    &lt;/div&gt;<br>  )<br>}<br><br>export default GiftPicture;</pre><p>The first thing we will do is import the { useDrag } hook. This hook connects our component to the dnd system as a drag source. Next, we are going to use various methods to build our draggable items.</p><pre>const [{ isDragging }, drag] = useDrag(() =&gt; ({<br><br>  }));</pre><p>We start by grabbing two things —</p><ol><li>isDragging: a boolean, which returns true when the item is being dragged, and false when it is not</li><li>drag: used as a reference for what we want to make draggable</li></ol><p>Next, we set these equal to the { useDrag } hook, which is a function that returns an object.</p><pre>const [{ isDragging }, drag] = useDrag(() =&gt; ({<br>        type: &quot;image&quot;,<br>        item: { id: id },<br>        collect: (monitor) =&gt; ({<br>            isDragging: !!monitor.isDragging()<br>        })<br>   }));</pre><p>Our object has three key value pairs —</p><ol><li>type: used to assign items to a specific drop target. Can be a string or symbol.</li><li>item: an object describing the data being dragged. Using id is a small amount of data, but easily recognizable.</li><li>collect: (optional) a method that aids in the tracking of the drag and drop state. This will allow us to tap into the isDragging boolean.</li></ol><p>Now to make our item actually draggable, we need to add some things to our img tag. In our return —</p><pre>   return (<br>        &lt;div&gt;<br>            &lt;img<br>                src={url}<br>                ref={drag}<br>                style={{ border: isDragging ? &quot;5px solid #fff&quot; : &quot;0px&quot; }}<br>            /&gt;<br>        &lt;/div&gt;<br>    )</pre><p>Each image is now draggable! Because our ref={drag} , our image knows what to do. You will notice we also used the isDragging boolean to say ‘if the image is currently being dragged, add a 5px, solid white border to it. Otherwise, no border.’ Lastly, because we mapped through the images, they are able to do this all independently from one another.</p><p>Our final GiftPicture component looks like this —</p><pre>import { useDrag } from &quot;react-dnd&quot;;<br><br>function GiftPicture({ url, id }) {<br><br>    const [{ isDragging }, drag] = useDrag(() =&gt; ({<br>        type: &quot;image&quot;,<br>        item: { id: id },<br>        collect: (monitor) =&gt; ({<br>            isDragging: !!monitor.isDragging()<br>        })<br>    }));<br><br>    return (<br>        &lt;div&gt;<br>            &lt;img<br>                src={url}<br>                ref={drag}<br>                style={{ border: isDragging ? &quot;5px solid #fff&quot; : &quot;0px&quot; }}<br>            /&gt;<br>        &lt;/div&gt;<br>    )<br>}<br><br>export default GiftPicture;</pre><h4>We’re Almost There</h4><p>Last step is to finish our DragDrop component. There are a few steps to this. Step one is importing the{ useDrop } hook. This hook allows us to bring in out component as a drop target. We will also need to import { useState }.</p><p>We set up very similarly to our { useDrag } hook with a few differences. Instead of isDragging to keep track of whether or not our item is being dragged, we use isOver to keep track of if it’s been dropped or not. Also, we use the drop value as our reference in place of drag.</p><pre>const [{ isOver }, drop] = useDrop(() =&gt; ({<br><br>  }));</pre><p>Inside of the object we will still use the collect method, incredibly similar to how we used it with the { useDrag } hook. Instead of type and item, though, we will use accept and drop. Let’s take a look —</p><pre>const [tree, setTree] = useState([]);<br><br>const [{ isOver }, drop] = useDrop(() =&gt; ({<br>        accept: &quot;image&quot;,<br>        drop: (item) =&gt; addImageUnderTree(item.id),<br>        collect: (monitor) =&gt; ({<br>            isOver: !!monitor.isOver()<br>        })<br>  }));<br><br>const addImageUnderTree = (id) =&gt; {<br>        const giftPictureList = GiftPictures.filter((giftPicture) =&gt; id === giftPicture.id);<br>        setTree((tree) =&gt; [...tree, giftPictureList[0]]);<br>  }<br><br></pre><p>Step by step, here is how this works.</p><ol><li>We are using state. I called mine tree and setTree because we are dragging our items under a Christmas tree. My default state is an empty array.</li><li>Instead of the type key, we are using accept. Our type was “image”, and so we want our drop target to accept the type of “image”.</li><li>The drop key is going to call this function each time we drop our item in the drop target. The function called is addImageUnderTree.</li><li>Within this function we filter through the images id to find the matching id passed in as an arguement. Once found, we update our tree state using the ... spread operator to add our giftPicture to our giftPictureList.</li></ol><p>One of the last things we need to do is map through this new list of pictures, and set up our reference for our drop.</p><pre>&lt;div ref={drop}&gt;<br>  {tree.map((giftPicture) =&gt; {<br>    return &lt;GiftPicture url={giftPicture.url} id={giftPicture.id} /&gt;;<br>  })}<br>&lt;/div&gt;</pre><p>Just like we did with our list of original GiftPictures , we map through to display them each in our tree state. We also set the ref of the div to ={drop}. Our entire DragDrop component will look like this now —</p><pre>import GiftPicture from &quot;./GiftPicture&quot;;<br>import React, { useState } from &quot;react&quot;;<br>import { useDrop } from &quot;react-dnd&quot;;<br><br>const GiftPictures = [<br>    {<br>        id: 1,<br>        url:<br>          &quot;url&quot;<br>    },<br>    {<br>        id: 2,<br>        url:<br>          &quot;url&quot;  <br>    },<br>    {<br>        id: 3,<br>        url:<br>          &quot;url&quot;<br>    }<br>];<br><br>function DragDrop() {<br>    const [tree, setTree] = useState([]);<br><br>    const [{ isOver }, drop] = useDrop(() =&gt; ({<br>        accept: &quot;image&quot;,<br>        drop: (item) =&gt; addImageUnderTree(item.id),<br>        collect: (monitor) =&gt; ({<br>            isOver: !!monitor.isOver()<br>        })<br>    }));<br><br>    const addImageUnderTree = (id) =&gt; {<br>        const giftPictureList = GiftPictures.filter((giftPicture) =&gt; id === giftPicture.id);<br>        setTree((tree) =&gt; [...tree, giftPictureList[0]]);<br>    }<br><br>    return (<br>        &lt;div&gt;<br>            &lt;div&gt;<br>                {GiftPictures.map((giftPicture) =&gt; {<br>                    return &lt;GiftPicture url={giftPicture.url} id={giftPicture.id} /&gt;;<br>                })}<br>            &lt;/div&gt;<br>            &lt;div ref={drop}&gt;<br>                {tree.map((giftPicture) =&gt; {<br>                    return &lt;GiftPicture url={giftPicture.url} id={giftPicture.id} /&gt;;<br>                })}<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    )<br>};<br><br>export default DragDrop;</pre><h4>Dragged and Dropped!</h4><p>At this point we are able to successfully drag and drop! There are a lot of steps, and honestly, sometimes it takes coding it to fully grasp all that is going on. My hope is this article can act as a helpful reference and foundation as you build your drag and drop project!</p><p>To visit the deployed project, click <a href="https://kaitlyngreve.github.io/drag-and-drop-mini-project/">here</a>. To visit the GitHub repo, click <a href="https://github.com/kaitlyngreve/drag-and-drop-mini-project">here</a>!</p><p>Have fun, and happy coding! 🥳</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39d34e358c4" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/a-christmas-drag-drop-with-react-dnd-39d34e358c4">A Christmas Drag &amp; Drop — With React DnD</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Grid — Step by Step]]></title>
            <link>https://towardsdev.com/css-grid-step-by-step-aad05ec91f4b?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/aad05ec91f4b</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css-grid-layout]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Fri, 09 Dec 2022 22:03:30 GMT</pubDate>
            <atom:updated>2022-12-19T20:04:43.120Z</atom:updated>
            <content:encoded><![CDATA[<h3>CSS Grid — Step by Step</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*NJqZtTtynXn9pwzDLfbKTg.jpeg" /></figure><p>Whether you are new to CSS grid or simply need a refresher with some easy to follow steps — you have clicked on the right post! My hope for you is that by the end of reading this post you have confidence in implementing a CSS grid in your project.</p><p>Grid layouts are incredibly common, not to mention fundamental, in the design of a functional and appealing web page or app. The CSS grid layout not only makes it easy to implement a grid, it is also versatile and customizable for your design needs. With the grid layout, you can align elements into columns and rows — much like the table layout. Unlike table, many more layout possibilities are available to grid users. Let’s say you wanted one of your grid child elements to overlap and layer one another — that is possible with the grid layout!</p><p>It is also worth mentioning that CSS grid properties have native support by major browsers (Safari, Chrome, Firefox, Edge).</p><p>CSS grid is a great tool for any front-end developer to have in their tool box. So, let’s get to it!</p><p>At the end of the post I have attached my GitHub repo — where I have my styling included for my grid demos.</p><h4>Building the Grid Layout</h4><p>To create your grid, there are two main components. The <strong>wrapper</strong> (parent) and the <strong>items</strong> (children).</p><ul><li><strong>Wrapper</strong> — the actual grid</li><li><strong>Items</strong> — the content that fill the grid</li></ul><p>In our html, here is what the code would look like.</p><pre>        &lt;div class=&quot;grid-wrapper&quot;&gt;<br>            &lt;div class=&quot;one&quot;&gt;1&lt;/div&gt;<br>            &lt;div class=&quot;two&quot;&gt;2&lt;/div&gt;<br>            &lt;div class=&quot;three&quot;&gt;3&lt;/div&gt;<br>            &lt;div class=&quot;four&quot;&gt;4&lt;/div&gt;<br>            &lt;div class=&quot;five&quot;&gt;5&lt;/div&gt;<br>            &lt;div class=&quot;six&quot;&gt;6&lt;/div&gt;<br>        &lt;/div&gt;</pre><p>The <strong>wrapper </strong>is the outer div with the class of “grid-wrapper”. Each div inside of the wrapper are the <strong>items</strong>.</p><p>Here is how this will look so far —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXd7Wc6NuCzw-vh96-l0NQ.png" /><figcaption>I’ve added styling to my grid — which you can view in my GitHub repo</figcaption></figure><p>Just a bunch of div‘s stacked on top of each other.</p><p>So, how do we turn it into a grid? Simple — we give our <strong>wrapper</strong> a display of grid.</p><pre>.grid-wrapper {<br>    display: grid;<br>}</pre><p>That doesn’t change anything yet. It is still 6 div‘s stacked on top of one another. To add some actual layout, we utilize columns and rows.</p><h4>Adding Columns and Rows to the Grid</h4><p>The two properties to add columns and rows are —</p><p>grid-template-columns</p><p>grid-template-rows</p><p>To start, let’s add two columns and three rows. Here is the markup.</p><pre>.grid-wrapper {<br>    display: grid;<br>    grid-template-columns: 100px 100px;<br>    grid-template-rows: 50px 50px 50px;<br>}</pre><p>We have given two values to the grid-template-columns property, so there will be two columns. Likewise, the grid-template-rows property was given three values, and so we will see three rows.</p><p>These values dictate how wide we want our columns and how tall we want our rows. In this example, our columns are 100px wide, and each row is 50px tall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*GUhFHDmeqryNOg5PvQ-IRA.png" /></figure><p>Let’s visualize these properties again, but with different values — to really ensure we understand the correlation with the grid values and the grid.</p><p>Here is another example —</p><pre>.grid-wrapper {<br>    display: grid;<br>    grid-template-columns: 100px 200px 50px 300px;<br>    grid-template-rows: 50px 60px;<br>}</pre><p>We have four columns, each with a different width. The first width is 100px, then 200px, 50px, a lastly 300px. We have only two rows, the first row is 50px tall, and the next one is 60px.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GK0Um_kxF9NaRyVfg5f3zA.png" /></figure><p>Do you understand? Let’s look at one more and try and break it down yourself!</p><pre>.grid-wrapper {<br>    display: grid;<br>    grid-template-columns: 450px 130px 70px;<br>    grid-template-rows: 50px 85px 100px;<br>}</pre><p>Here is how the code plays out —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eUmNi8nceNym6TlSyVDOWg.png" /></figure><p>Hopefully, at this point you have a firm grasp on the relationship between the two grid properties, grid-template-columns, and grid-template-rows, their values, and how it represents the end grid.</p><h4>How to Change Placement of the Items</h4><p>CSS grid also allows you to effortlessly change the placement of each individual item. This is the real hero of CSS grid, and allows you to create simple and easy to design layouts.</p><p>First, we are going to reset our grid. Let’s go with a 3x3.</p><pre>.grid-wrapper {<br>    display: grid;<br>    grid-template-columns: 100px 100px 100px;<br>    grid-template-rows: 100px 10px 100px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*G1muj4F_sDAdmzViPoKUYw.png" /></figure><p>It’s worth noting — we defined a 3x3 grid, right? So why are we only seeing a 3x2? That is simply because we have only six items in our grid. If we added three more items, they would fill in the remaining grid rows.</p><p>Like —</p><pre>        &lt;div class=&quot;grid-wrapper&quot;&gt;<br>            &lt;div class=&quot;one&quot;&gt;1&lt;/div&gt;<br>            &lt;div class=&quot;two&quot;&gt;2&lt;/div&gt;<br>            &lt;div class=&quot;three&quot;&gt;3&lt;/div&gt;<br>            &lt;div class=&quot;four&quot;&gt;4&lt;/div&gt;<br>            &lt;div class=&quot;five&quot;&gt;5&lt;/div&gt;<br>            &lt;div class=&quot;six&quot;&gt;6&lt;/div&gt;<br>            &lt;div class=&quot;seven&quot;&gt;7&lt;/div&gt;<br>            &lt;div class=&quot;eight&quot;&gt;8&lt;/div&gt;<br>            &lt;div class=&quot;nine&quot;&gt;9&lt;/div&gt;<br>        &lt;/div&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*bTQhVLYHNtMXa0DkfC4Jiw.png" /></figure><p>Good to know CSS grid does that! But, for the remaining examples, we are going to return to our six item grid.</p><p>Now, we are going to play with the position and size of each of our grid items.</p><p>To eliminate any confusion in the next step, let’s start by discussing how to know how many grid lines we have. It might now make sense yet, but stay with me. We have three columns, but four grid lines. Take a look at the example below.</p><p>I have highlighted our grid lines in black.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*lGwtZvMC62UOnMpSQhSI5Q.png" /></figure><p>So now, as we position and resize the grid items, we know how many grid lines to use to utilize the entire column. To do this, we use two properties, grid-column, and grid-row. I will show you, and then break it down.</p><p>The markup looks like this —</p><pre>.one {<br>    grid-column-start: 1;<br>    grid-column-end: 4;<br>}</pre><p>It plays out like this —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*LFt1MTahC9Qu3lQGiHpR5g.png" /></figure><p>On our first item we are declaring that it begins at column (or grid line) 1, and ends at column (or grid line) 4.</p><p>Next, I did a lot of changing to our grid layout. See if you can work through the relation between the values and their place on the grid.</p><pre>.one {<br>    grid-column-start: 1;<br>    grid-column-end: 4;<br>}<br><br>.two {<br>    grid-row-start: 2;<br>    grid-row-end: 4;<br>}<br><br>.three {<br>    grid-column-start: 2;<br>    grid-column-end: 4;<br>}<br><br>.four {<br>    grid-column-start: 2;<br>    grid-column-end: 3;<br>}<br><br>.five { <br>    grid-column-start: 3;<br>    grid-column-end: 4;<br>}<br><br>.six {<br>    grid-row-start: 4;<br>    grid-column-start: 1;<br>    grid-column-end: 4;<br>}</pre><p>Here is how it would play out —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*guugSqZdIYUpAAyX6CCS-g.png" /></figure><p>Here is where it all comes together. Do you see how you might be able to put together a website layout fairly effortlessly? I have put together some super simple code to demonstrate how you can use CSS grid in your next webpage layout!</p><p>I did not change anything about our grid layout, only the content of each item. It is a great visualization, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*70FgUiq1DFIggVI79lwMEg.png" /></figure><h4>What Else Can CSS Grid Do?</h4><p>CSS grid has several properties you can implement into your code to further customize your grid.</p><p>Take the gap property for example —</p><ul><li>row-gap: sets a gap between rows</li><li>column-gap: sets gap between columns</li><li>gap: shorthand for row-gap &amp; column-gap. Allows you to set them both in one property</li></ul><p>There are also many shorthand variations for all the properties we have used in this article. Visit this <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout">link</a> if you want to check out more!</p><h4>We Did It!</h4><p>In this article we learned and implemented CSS grid to customize our grid layout. I hope each step was simple to follow and you have confidence to give it a go in your own project!</p><p>I recommend going in and trying these properties for yourself. Play around with the placement and size of each value, and notice its relation to the final grid layout. As I mentioned earlier in the article, I attached my <a href="https://github.com/kaitlyngreve/CSSGridDemo">Github repo</a>—feel free to check it out and utilize it for your own CSS grid.</p><p>Happy coding! 😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aad05ec91f4b" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/css-grid-step-by-step-aad05ec91f4b">CSS Grid — Step by Step</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Knowing Linked Lists for JavaScript Developers]]></title>
            <link>https://towardsdev.com/knowing-linked-lists-for-javascript-developers-87adfdb87838?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/87adfdb87838</guid>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Wed, 07 Dec 2022 19:33:00 GMT</pubDate>
            <atom:updated>2022-12-09T11:19:49.481Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U1-R54TrsO7jiBTWOieDSw.jpeg" /></figure><p>Considered a “core” data structure, linked lists may seem a little cumbersome to a JavaScript developer. After all, we have arrays built into JavaScript. So why spend the time with other data structures?</p><p>Imagine data structures are Lego bricks. Each data structure you know is a different kind of brick. Some 2x2’s, 2x4’s, 1x6’s … you get the picture. The code you write, that is a Lego structure. Could you put together a dimensional Lego structure with one kind of brick? Absolutely. But think of the exponentially more possibilities with all different kinds of bricks.</p><p>Let’s add another lego brick!</p><h4>What is a Linked List?</h4><p>A linked list is linear data structure where each element is not stored at contiguous memory locations. The elements in a linked list are not directly adjacent to its neighboring element. Instead, each linked list element is linked using pointers. These ‘elements’ are called nodes. Look at example (b) below. Each node consists of two fields.</p><ol><li>Information stored in a linked list</li><li>Pointer that stores the address of its next node</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQbxPs4hB_O4e7vccLwB5A.png" /><figcaption>Diagram of a Contiguous vs Non-Contiguous (Credit: <a href="https://examradar.com/introduction-data-structures/contiguous-and-non-contiguous-structures/">Examrader</a>)</figcaption></figure><p>At the start of a linked list, the address has its own name. That first node is called head. It is also worth noting that the last node in a linked list contains null because it does not point to anything.</p><p>To summarize our intro to linked lists so far, a linked list is:</p><p>A linked list is built of nodes and, starting with the head, each contain a data field and a reference (address) to the next node in the list.</p><h4>The Three Main Types of Linked Lists</h4><p>Linked lists appears in three main types.</p><ol><li>Singly Linked List</li><li>Doubly Linked List</li><li>Circular Linked List</li></ol><p><strong>Singly Linked List —</strong></p><p>This type of the linked list is definitely the most common. In the singly linked list, each node contains data and a reference to the next node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/0*5ntS6cS5q8Y_C67l.png" /><figcaption>Diagram of a Singly Linked List (Credit: <a href="https://www.geeksforgeeks.org/circular-linked-list/">GeeksForGeeks</a>)</figcaption></figure><p><strong>Doubly Linked List —</strong></p><p>The doubly linked list contains two reference pointers. The first pointer points to the previous node, and the last pointer points ahead to the next node. In a doubly linked list, you can move both forward and backward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/0*NEjv1_-Qau_Zos29.png" /><figcaption>Diagram of a Doubly Linked List (Credit: <a href="https://www.geeksforgeeks.org/circular-linked-list/">GeeksForGeeks</a>)</figcaption></figure><p><strong>Circular Linked List —</strong></p><p>With the circular linked list, it acts similar to the singly linked list except the last node does not contain null , but instead contains a reference to the head of the linked list. As the name suggests, it follows a circular pattern. The circular linked list can be either a singly OR doubly linked list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*FJ9sN0vqw2CaK2fW.png" /><figcaption>Diagram of a Circular Linked List (Credit: <a href="https://www.geeksforgeeks.org/circular-linked-list/">GeeksForGeeks</a>)</figcaption></figure><h4>Building a Simple Linked List</h4><p>To better understand some of the advantages and disadvantages of linked lists, let’s build one to utilize later on. Unlike creating an array like [1,2,3,4] , we need to build our linked list node by node.</p><p><strong>Step 1:</strong></p><p>Initialize a variable called list and set it to null.</p><pre>let list = null;</pre><p><strong>Step 2:</strong></p><p>Each node will be represented as an object with two properties.</p><ol><li>A value</li><li>A reference to the next node</li></ol><pre>let node = {<br>  value: 1,<br>  next: null<br>}</pre><p><strong>Step 3:</strong></p><p>Lovely. Now our node is a list with one value. We are going to want to be able to add to our list, so we can build a function to do that.</p><pre>function createNode(value) {<br>  return {<br>    value: value,<br>    next: null<br>  }<br>}</pre><p><strong>Step 4:</strong></p><p>We can now create more nodes!</p><pre>let nodeOne = createNode(1);<br>let nodeTwo = createNode(2);<br>let nodeThree = createNode(3);<br>let nodeFour = createNode(4);</pre><p><strong>Step 5:</strong></p><p>With our nodes created, we can link our list.</p><pre>nodeOne.next = nodeTwo;<br>nodeTwo.next = nodeThree;<br>nodeThree.next = nodeFour;</pre><p>We created four different nodes and linked them together by assigning each node’s .next pointer a reference/address to the next node.</p><p>Again, this is an incredibly simple linked list. In the next section, I discuss the advantages and disadvantages of linked lists. The examples included in this section are using a JavaScript Linked List Class, which looks a little different from what we did above. If you are interested in diving into it a bit more, I have linked a great resource at the end of this post.</p><h4>Advantages and Disadvantages of Linked Lists</h4><p>Let’s compare the pros and cons of linked lists.</p><p><strong>Advantages —</strong></p><p>Unlike arrays, nodes in a linked list can be easily added or removed without the entire data structure being reorganized.</p><p>Let’s bring BigO into this. Adding or removing a node in a linked list has a BigO of O(1). Meaning — constant time. It will *always* take the same amount of time to execute. Let’s look at an example:</p><pre>/*<br>Because Javascript doesn&#39;t have native support for <br>Linked Lists, we use a class to implement one.<br>*/<br><br>class LinkedList {<br>    constructor(value) {<br>        this.head = null;<br>        this.length = 0;<br>        this.insert(value);<br>    }<br>    <br>    insert(value) {<br>        const newNode = { value }; <br>        newNode.next = this.head;  <br>        this.head = newNode;       <br>        this.length++;<br>        return this;<br>    }<br>}<br><br>// Now create the actual list, and insert two items afterwards.<br>const list = new LinkedList(&#39;List Item One&#39;)<br>    .insert(&#39;List Item Two&#39;)<br>    .insert(&#39;List Item Three&#39;);</pre><p>The insert method is adding new values to our lists. Our (Javascript) linked list object would now look like this:</p><pre>{<br>    length: 3,<br>    head: {<br>        value: &#39;List Item One&#39;,<br>        next: {<br>            value: &#39;List Item Two&#39;,<br>            next: {<br>                value: &#39;List Item THree&#39;,<br>                next: null<br>            }<br>        }<br>    }<br>}</pre><p>Notice the next ? That is the reference to the next node :)</p><p>With arrays, we could use the array.unshift or array.shift to add or remove — BUT — because arrays are stored at specific indices, each time you add or remove from an array, every subsequent item in the array has to be shifted over to the next index. This gives adding or removing from arrays the BigO of O(n). So, linear time complexity. This means the time it will take to run will increase proportionately as the size of input <em>n </em>increases. In other words, not necessarily ideal.</p><p><strong>Disadvantages —</strong></p><p>First, linked lists take up more memory. This is because linked lists have to not just store the data within each node, but also the pointers to the next node.</p><p>Second, searching operations in linked lists are a drag. They’re slow! In order to search, nodes are accessed sequentially starting from the first node. Let’s reference our linked list object from earlier:</p><pre>{<br>    length: 3,<br>    head: {<br>        value: &#39;List Item One&#39;,<br>        next: {<br>            value: &#39;List Item Two&#39;,<br>            next: {<br>                value: &#39;List Item Three&#39;,<br>                next: null<br>            }<br>        }<br>    }<br>}</pre><p>What if we want to access our &#39;List Item Three&#39; . Well, we would have to go down the line until we get to the node we want.</p><pre>list.head.next.next.value; // &#39;List Item Three&#39;</pre><p>Imagine if the list were much, much longer. We have to traverse our way down until we get to what we’re looking for. With arrays we just have to access the specific index we are looking for. If we have this linked list but array form:</p><pre>array = [<br>  0: &#39;Array Item One&#39;,<br>  1: &#39;Array Item Two&#39;,<br>  2: &#39;Array Item Three&#39;<br>]</pre><p>To find our item we use:</p><pre>array[2] // &#39;Array Item Three&#39;</pre><h4>What We’ve Learned</h4><p>In this post we have covered what a linked list is, the three main types, and both advantages and disadvantages.</p><p>Linked lists can be fantastic when you need quick insertion and deletion, but can sacrifice timing with searching and overall space taken.</p><p>I hope you have found this post helpful!</p><p>Here is the resource to <a href="https://www.freecodecamp.org/news/implementing-a-linked-list-in-javascript/">how to implement linked lists in JavaScript</a>.</p><p>Happy coding 😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87adfdb87838" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/knowing-linked-lists-for-javascript-developers-87adfdb87838">Knowing Linked Lists for JavaScript Developers</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using localStorage in React]]></title>
            <link>https://towardsdev.com/using-localstorage-in-react-99115822e940?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/99115822e940</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[to-do-list]]></category>
            <category><![CDATA[localstorage]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Mon, 07 Nov 2022 17:06:09 GMT</pubDate>
            <atom:updated>2022-11-08T14:27:36.513Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3CS8vzdKHrYnq-9aVdJ7g.png" /></figure><p>My most recent project has been building a simple to-do app, Taskier. The app allows the user to create a task, mark the task as completed, edit the task, and finally, delete the task. Early on I realized that upon a page refresh — everything would be wiped. Meaning tasks that had been listed and checked as completed … gone. That’s a pretty pointless to-do app.</p><p>For this project, I used <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage">localStorage</a> with React Hooks. One of two web storage API mechanisms, localStorage allows data to be stored as key-value pairs for later use.</p><p>The second mechanism is <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage">sessionStorage</a>, which is what is sounds like. With sessionStorage, data persists in the browser storage only as long as the current browser tab is running.</p><p>If you are interested in giving localStorage a try — it is great for implementing a dark mode feature in your application, persisting a user’s form input values, and, what I am covering today, saving to-do items.</p><h4>How to Implement localStorage in our React Application</h4><p>localStorage allows us access to a browsers storage object and includes five methods.</p><ul><li>setItem() : This method is used to add a key and value to localStorage</li><li>getItem() : This method is used to get an item in localStorage based on it’s key</li><li>removeItem() : This method is used to delete and item in localStorage based on it’s key</li><li>clear() : This method is used to delete ALL instances in localStorage</li><li>key() : This method will retrieve a localStorage item when you supply it a number</li></ul><p>For persisting our to-do list items, we will be using the two most popular localStorage methods:</p><ul><li>setItem()</li><li>getItem()</li></ul><p>In addition to understanding localStorage and it’s methods, you need to know about React Hooks.</p><h4>What are React Hooks?</h4><p>Hooks, introduced in React 16.8, are JavaScript functions that let you ‘hook into’ React state and lifecycle features from functional components.</p><p>If you have not heard of hooks, or want to learn more about them, I linked ‘Hooks at a Glance’ from the React documentation at the end of this post.</p><p>In order to use localStorage with React Hooks, we will be looking at two specific hooks.</p><ul><li>useState() : This hook is a function that accepts one parameter, the initial state, and returns two values: the current state and a function that can be used to update the state. This hook is useful because the state of your application is guaranteed to change.</li><li>useEffect() : The Effect Hook is initiated by default after the initial render and each time state is updated. Think of it like this, the Effect Hook is used to perform an effect each time the state changes.</li></ul><p>Now that we have some base understanding of localStorage, its methods, and the State and Effect hooks, let’s look at some code!</p><h4>Step 1 —</h4><p>Implementing the setItem() method.</p><p>The setItem() method is giving a value to a key to store in out localStorage object. Whether it’s text, an integer, object, or array — this value can be any datatype. Let’s look at the code block, and take it line by line.</p><pre>const [todos, setTodos] = useState([]);</pre><pre>useEffect(() =&gt; {<br>   const temp = JSON.stringify(todos);<br>   localStorage.setItem(&quot;todos&quot;, temp);<br>}, [todos]) </pre><p>First, we created state and set its default as an empty array. This could be any datatype, but for this case, it’s an empty for now. Next, we are using the Effect hook to add objects to our localStorage whenever the value of that state is changed — which we managed by passing our state in as the second argument.</p><p>That leaves us with what is happening inside the useEffect() :</p><pre>localStorage.setItem(&quot;todos&quot;, JSON.stringify(todos));</pre><p>The above line of code is responsible for adding those key-value pairs to localStorage. Simply put, this code names the key (argument #1) and assigns a value to it (argument #2). In order to store the data correctly, we need to convert the JSON object into JSON text — which we do using JSON.stringify() . So now, when our todos state changes, we ‘set’ that key-value pair and store it.</p><h4>Step 2 —</h4><p>Implementing the getItem() method.</p><p>This method … as you can guess … gets our object from localStorage. Like we did with setItem() , we could set up a similar situation with the Effect hook and on each page load ‘get’ our items from localStorage. It might look something like this —</p><pre>const [todos, setTodos] = useState([]);</pre><pre>useEffect(() =&gt; {<br>   const todos = JSON.parse(localStorage.getItem(&#39;todos&#39;));<br>  if (todos) {<br>   setTodos(todos);<br>  }<br>}, []);</pre><p>I, however, went a different route. My code looks like this —</p><pre>const savedTodos = localStorage.getItem(&quot;todos&quot;);</pre><pre>const [todos, setTodos] = useState(savedTodos ? JSON.parse(savedTodos) : []);</pre><p>Ok, what?</p><p>I set my localStorage.getItem(&quot;todos&quot;) to a constant variable I named savedTodos . It made my code a little cleaner and easier to read. Next, my default state is set as a ternary operator. We’re asking:</p><ol><li>Are there savedTodos?</li><li>Yes? Awesome. Take those savedTodos, which are currently JSON text and turn it into a JavaScript object. Now show us the todos!</li><li>No? Well, give us an empty array then.</li></ol><p>And there you have it.</p><p>Now our todo list works! And there is no escaping the ever growing task list 🫣 You’re welcome.</p><p><a href="https://reactjs.org/docs/hooks-overview.html">Here</a> is the promised land for all things React Hooks.</p><p>And <a href="https://github.com/kaitlyngreve/taskier-a-todo-react-app">here</a> you can find the source code for the completed todo list 🥳</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99115822e940" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/using-localstorage-in-react-99115822e940">Using localStorage in React</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Flexbox]]></title>
            <link>https://medium.com/@kgreve14/css-flexbox-28d11dc42891?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/28d11dc42891</guid>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Tue, 02 Aug 2022 15:12:12 GMT</pubDate>
            <atom:updated>2022-08-02T15:23:25.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*psDzMFGiXgy3fEvb" /></figure><p>CSS can be intimidating. Not because it is overly complicated or causes errors, (actually … part of why CSS can be tricky is because it does not cause errors 😅), but because it can do so many things! During my bootcamp, a cohort mate and I would joke that CSS felt like an endless hole — once you started, it was hard to stop. I do recognize that hole isn’t always fun, though. I have put together a simplified tutorial on one of my favorite aspects of CSS — Flexbox. The flexbox layout is provides an efficient way to lay out, align and distribute space among items in a container. It does this even when their size is unknown and/or dynamic (hence the use of the word “flex”).</p><p><strong>Before you use something, it is best to know *why* we might use it. Let’s explore the ‘what’ and ‘why’ of flexbox.</strong></p><p>The main idea behind the flex layout is flexibility. Flexbox is designed to give the container the ability to alter the items’ (within the container) width and height and fill the space available. The flex container (the container holding the individual items) expands those items to fill available free space OR shrinks the items to prevent overflow. If you shrink your screen right now (go ahead and do it … I’m waiting) do you still see all of the information just smaller or more condensed? That is the idea!</p><p>Another thing of note — flexbox is direction agnostic. Meaning, it’s free from any direction constraints. Compare this to our other layouts like block, which is vertically-based, and inline which is horizontally-based.</p><p><strong>Flexbox comes with its own terminology, too.</strong></p><p>Let’s use this image for reference:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ORzvuTjOpBU4bGtF.png" /></figure><p>Just like our other layouts, we are based on the <em>container</em> and <em>item</em> concept. In the flexbox model, our container is known as the <strong><em>flex-container</em></strong>, which is the outer most element / parent. Within that, we have the <strong><em>flex-items</em></strong>, which are the child elements of the parent ‘<strong><em>flex-container</em></strong>’.</p><p>In the flex layout, the <strong><em>flex-items</em></strong> will be laid out following either the main axis (from main-start to main-end) or the cross axis (from cross-start to cross-end). In the layout above, the main axis is horizontal, meaning the cross axis is vertical.</p><ul><li><strong>main axis</strong> — The main axis of a flex container is the primary axis along which flex items are laid out. It is not necessarily horizontal, though, that depends on the flex-direction property.</li><li><strong>main-start | main-end</strong> — The flex items are set within the container starting from main-start and going to main-end. (pretty self explanatory)</li><li><strong>main size</strong> —Whichever is in the main dimension, (this could mean its width or height), is the item’s main size.</li><li><strong>cross axis</strong> — The axis perpendicular to the main axis is called the cross axis. Its direction depends on the main axis direction.</li><li><strong>cross-start | cross-end</strong> — Flex items are placed into the container starting on the cross-start side of the flex container and going toward the cross-end side.</li><li><strong>cross size — </strong>Whichever is in the cross dimension, (height or width), is the item’s cross size.</li></ul><p><strong>Now, let’s use it.</strong></p><p>I am going to lay down some of the most popular properties flexbox has to offer. There are several, though, so know I have not completed a complete guide. These first properties are to use on our container. Later on, we will look at properties for the item within the container .</p><h4>display</h4><p>Display is what we use to define a block, inline, or flex container. We will want to use flex as our value, as we are learning about flexbox.</p><pre>.container {<br>   display: flex;<br>}</pre><h4>flex-direction</h4><p>Using flex-direction is what defines the main-axis. By defining the direction, we are laying out flex-items in either a horizontal row or vertical column.</p><pre>.container {<br>   flex-direction: row | row-reverse | column | column-reverse;<br>}</pre><blockquote>note: row is the default</blockquote><h4>justify-content</h4><p>With justify-content, we define the alignment along the main axis. This will distribute extra free space whether all the flex items on a line are inflexible, or are flexible — but have reached their maximum size.</p><pre>.container {<br>   justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly ...;<br>}</pre><blockquote>note: there are plenty of ways to use justify-content. I have included the BEST ‘cheat sheet’ at the end of this blog.</blockquote><h3>OK … feeling like a flexbox pro yet?</h3><p>If not, that is a-ok! Remember, the best way to learn is to get on VSCode (or whatever coding software you use) and practice!</p><p>Ok, let’s dive into some item properties.</p><h4>flex-grow</h4><p>By defining this, we give the flex-item to grow if necessary. Flex-grow accepts a unit-less number/value that serves as a proportion.</p><p>“If all items have flex-grow set to 1, the remaining space in the container will be distributed equally to all children. If one of the children has a value of 2, that child would take up twice as much of the space either one of the others (or it will try, at least).” (<a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/#aa-justify-content">the best cheat sheet ever</a>)</p><pre>.item {<br>   flex-grow: 1;<br>}</pre><h4>flex-shrink</h4><p>Yup, you’re right. This gives the item the ability to shrink!</p><pre>.item {<br>   flex-shrink: 2;<br>}</pre><blockquote>note: negative numbers are invalid</blockquote><h4>flex-basis</h4><p>Flex-basis defines the default size of an element before the remaining space is distributed. You can use either a length (e.g. 10rem, 15%, etc.) or a keyword. The auto keyword means “look at my width or height property”. There is also the content keyword — which is not fully supported yet. But, this keyword looks at the items content and says “size the item based on the item’s content”.</p><pre>.item {<br>   flex-basis: auto;<br>}</pre><h4>flex</h4><p>This combines flex-grow , flex-shrink , and flex-basis in one shorthand. When using this property, the second and third parameters are not required — flex-shrink , and flex-basis . Because of this, it is recommended to use this shorthand in place of three individual properties.</p><pre>.item {   <br>   flex: none;<br>}</pre><p><strong>See …</strong></p><p>CSS flexbox in a great tool for your frontend styling tool kit. I hope this blog was helpful in ‘getting your foot in the flexbox door’. Definitely check out this <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/#aa-justify-content">cheatsheet</a>. You will find more information on all of these properties, as well as visual representation of each one.</p><p>And remember, trying it out is one of the best ways to learn!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28d11dc42891" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[useHistory => useNavigate]]></title>
            <link>https://medium.com/@kgreve14/usehistory-usenavigate-5b383160adba?source=rss-f79c6d093535------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b383160adba</guid>
            <category><![CDATA[usehistory]]></category>
            <category><![CDATA[react-router]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Kaitlyn Greve]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 17:48:24 GMT</pubDate>
            <atom:updated>2022-07-19T17:48:24.901Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*GtFUO_Gixz73NmiV" /></figure><p>With ReactRouter updating from version 5 to version 6, there have been a few changes. One of which is the replacement of the useHistory() hook to useNavigate(). If you remember — the useHistory() hook accesses the ReactRouter history object and navigates to the other routers using push or replace methods. With this hook, you could navigate to the specific URL and move forward and backward pages with ease. As a fan of useHistory(), learning to useNavigate() was imperative.</p><p>Thankfully, for us useHistory() lovers, the changes are fairly simple, and ultimately use less code … who doesn’t love that?! Let’s break down some of the changes so you can use the new and improved hook with ease.</p><h4>useHistory()</h4><pre>import { useHistory } from &#39;react-router-dom&#39;;</pre><pre>function HomePage() {<br>   let history = useHistory()</pre><pre>   const handleClick = () =&gt; {<br>      history.push(&#39;/aboutpage&#39;)<br>   }</pre><pre>   return(<br>      &lt;button onClick={handleClick}&gt; Read More &lt;/button&gt;<br>   );<br>}</pre><p>The hook we know and love ^</p><p>Let’s take a closer look at what is going on:</p><ol><li>We import useHistory at the top of our component</li><li>We declare our history variable to our hook <em>(remember: that variable name can be anything, as long as it is assigned to the hook)</em></li><li>In our handleClick function — we use our variable, an action (.push), and the route we are wanting to navigate to</li><li>Assign our onClick to our button</li></ol><p>Per our simple breakdown of this hook, we would expect that clicking on the ‘Read More’ button would redirect us to the ‘/aboutpage’ route. As said at the beginning of this post, though, we said the useHistory() is old news. So — more importantly, how does useNavigate() work in comparison?</p><h4>useNavigate()</h4><p>Lucky for us, this hook behaves incredibly similar to it predecessor.</p><pre>import { useNavigate } from &#39;react-router-dom&#39;;</pre><pre>function HomePage() {<br>   let navigate = useNavigate()</pre><pre>const handleClick = () =&gt; {<br>      navigate(&#39;/aboutpage&#39;)<br>   }</pre><pre>return(<br>      &lt;button onClick={handleClick}&gt; Read More &lt;/button&gt;<br>   );<br>}</pre><p>Done investigating the differences? That looks *pretty* similar doesn’t it?</p><p>The most obvious change is the ability to leave the .push off the end of navigate . With useNavigate(), we do not need it! It will automatically push the user to whatever route is specified.</p><p>With useNavigate, we can:</p><ul><li>Pass a ‘to’ value (‘/aboutpage’ is our ‘to’ value)</li></ul><p>OR</p><ul><li>Pass in where you want to go in the history stack. Something like navigate(-1), which will act as a back button</li></ul><p>Like with useHistory(), we still have access to the actions like push, pop, and replace, it simply looks a little different!</p><h4>So really …</h4><p>The useNavigate() hook is simple to utilize and we need to implement less code — hooray! There are plenty of changes that were made between v5 and v6 of ReactRouter, so definitely check out those changes <a href="https://reactrouter.com/docs/en/v6">here</a>, and keep up to date!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b383160adba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>