<?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 starrdev on Medium]]></title>
        <description><![CDATA[Stories by starrdev on Medium]]></description>
        <link>https://medium.com/@personnamedmike?source=rss-949bd777c94e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PTUmVzqfqyAO4Ozu94IHxQ.jpeg</url>
            <title>Stories by starrdev on Medium</title>
            <link>https://medium.com/@personnamedmike?source=rss-949bd777c94e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:42:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@personnamedmike/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[My Hackathon Experience — Building a Music Streaming App]]></title>
            <link>https://medium.com/@personnamedmike/my-hackathon-experience-building-a-music-streaming-app-eb053911bbbd?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb053911bbbd</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Thu, 11 Aug 2022 15:48:34 GMT</pubDate>
            <atom:updated>2022-08-11T15:48:34.138Z</atom:updated>
            <content:encoded><![CDATA[<h3>My Hackathon Experience — Building a Music Streaming App</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*s5UDqBeZ0sYnulS8FoQZsw.png" /></figure><p>Yesterday I completed another hackathon. This was the “<a href="https://metabolism.ethglobal.com/">Metabolism</a>” hackathon, organized by <a href="https://medium.com/u/3d1733b8e86a">ETHGlobal</a>. It was my second real hackathon, and the experience was incredible.</p><p>The main sponsor of the event was <a href="https://zora.co/">Zora</a>. Zora is a hyperstructure built on the Ethereum blockchain, and has API’s that let you easily integrate your application with their NFT marketplace. Companies sponsor hackathons and offer prizes to participants, as a way to incentivize people to use their tech.</p><h3>My reasoning for signing up</h3><p>I joined this event for several reason:</p><ul><li>Add a new project to my <a href="https://mike-starr-portfolio.herokuapp.com/">portfolio</a></li><li>Learn more about the Ethereum ecosystem and new technologies</li><li>Network with more developers in the web3 community</li></ul><h3>Finding a team</h3><p>This time I got lucky and it was easy to find a team. After you signup and stake ETH for an ETH Global hackathon, they add you to a channel for the event in their Discord server.</p><p>On Discord, I posted about my technical experience and said I was looking for a team. Somebody reached out to me, and next thing I knew I was on a team with 3 others. This was the most distributed team I’ve ever been a part of. The 4 of us were located in Nigeria, South Africa, India and the United States.</p><h3>Ideation</h3><p>Before the hackathon officially started, I organized a group call over Zoom. The person who initially reached out to me had an idea to build a music streaming app. Artists can mint NFT’s on our platform. Advertisers can purchase an NFT which grants them time-gated access to display a banner ad when a specific song is played.</p><p>The guy who thought of this idea was not an engineer himself, but he had great ideas, and needed technical people to execute his ideas. This was a reminder for me that for a project to be successful, it’s helpful if the team has a wide range of skills. Not everybody needs to be an engineer, and not everybody needs to be a marketer either.</p><h3>Technical, nitty-gritty</h3><p>One person on the team worked on the back-end, and 2 of us worked on the front-end. Here’s a list of my technical contributions:</p><ul><li>Created React component structure in Next.js</li><li>Designed CSS components using TailwindCSS</li><li>Implemented Ant Design CSS components</li><li>Used Ethers.js to connect app to the Ethereum blockchain, and use WalletConnect to connect to users’ wallets of choice</li><li>Worked with a globally distributed team of 4 people and communicated on Discord. I set up Notion to document project ideas, and organized the team’s technical tasks as GitHub issues</li></ul><p>For the back-end, our smart contracts allow for users to mint NFT’s on our platform. After minting, these NFT’s are saved to Zora protocol’s marketplace, which means they can be sold on any app in Zora’s ecosystem.</p><p>Due to time constraints of the hackathon (only 3 days to build), we weren’t able to finish building all of the features, including the ad marketplace.</p><h3>Presenting to judges</h3><p>Everybody in the team was in different time zones, and I had the best internet connection, so we all decided that I should present. This was a fun experience for me, and I felt articulate in presenting the project to the event judges.</p><p>It went well, and we won a cash prize from the one of the event sponsors. NFT.storage! Making money from this event was great motivation, and validated a lot of the hard work we did.</p><h3>Conclusion</h3><p>Hackathons are a great way to lower your learning curve. It feels like weeks of experience condensed into a few days. I gained more experience building a UI, and it was helpful to work alongside more experienced developers.</p><p>If you’ve on the fence about doing a hackathon, I’d recommend it. The only downside is that I didn’t get much sleep, and spent my entire weekend (including nights) working on the project. It was worth the effort, and I plan on doing more hackathons in the near future.</p><p>GitHub repos:</p><ul><li>Front-end: <a href="https://github.com/meta-web3-music/frontend">https://github.com/meta-web3-music/frontend</a></li><li>Back-end: <a href="https://github.com/meta-web3-music/smart-contracts">https://github.com/meta-web3-music/smart-contracts</a></li></ul><p>My team and I are still working on the project, so I’ll update this post with a link to the app when it’s live.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb053911bbbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tailwind CSS Basics]]></title>
            <link>https://medium.com/@personnamedmike/tailwind-css-basics-c1fdf26ee61c?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1fdf26ee61c</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Mon, 25 Jul 2022 18:13:51 GMT</pubDate>
            <atom:updated>2022-07-25T18:13:51.231Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Tailwind CSS logo" src="https://cdn-images-1.medium.com/max/512/1*JEHLmWo6_SrpHPiP4AimIw.png" /></figure><p>I spent the past week building a <a href="https://mike-starr-portfolio.herokuapp.com/">personal portfolio app</a>. I used Tailwind CSS and React. It took me some time getting used to Tailwind CSS, but now I love it.</p><p>The documentation is great. It has explanations and photo diagrams which make it simple to implement the framework. <a href="https://tailwindcss.com/docs/installation">Read the docs here</a>.</p><h3>Installation</h3><p>I used create-react-app for my project, so if you’re using a different environment, check out the Tailwind CSS docs.</p><p>cd into your project directory and install Tailwind:</p><pre>$ npm install -D tailwindcss postcss autoprefixer<br>$ npx tailwindcss init -p</pre><p>The second line will initialize a new file called tailwind.config.js . In this file, copy paste the following code:</p><pre>module.exports = {<br>  content: [<br>    &quot;./src/**/*.{js,jsx,ts,tsx}&quot;,<br>  ],<br>  theme: {<br>    extend: {},<br>  },<br>  plugins: [],<br>}</pre><p>Next go to your css file ./src/index.css and add the following code:</p><pre>@tailwind base;<br>@tailwind components;<br>@tailwind utilities;</pre><p>Something to note is that with create-react-app , when you edit your tailwind.config.js file and make changes, you might need to run build scripts npm run build for your changes to take place.</p><p>Now we’re ready to go!</p><h3>Adding CSS elements to your code</h3><p>Here’s the basic syntax:</p><p>&lt;div <strong>className=&quot;&quot;</strong>&gt; add your styles to className=&quot;&quot; &lt;/div&gt;</p><p>Your styles will go within the parenthesis after className= . The syntax for class names is a bit different than traditional CSS, but is easy to lookup in the documentation.</p><p>In the example code below, we’ll compare the syntax of traditional CSS vs. Tailwind:</p><pre># traditional CSS:</pre><pre>.example {<br>  background-color: white;<br>  display: flex;<br>  margin: 1rem;<br>  padding: 2rem;<br>};</pre><pre>&lt;div class=&quot;example&quot;&gt;&lt;/div&gt;</pre><pre># Tailwind CSS:</pre><pre>&lt;div className=&quot;bg-white flex m-4 p-8&quot;&gt;&lt;/div&gt;</pre><p>Note that in Tailwind, m-4 corresponds to margin: 16px;</p><h3>Adding custom colors</h3><p>Out of the box, Tailwind CSS has classes such as: text-gray-300 and bg-black . But what if you want to add a custom color, such as #86BBD8?</p><p>The easiest solution is to put it into brackets. For example: text-[#86BBD8] .</p><h3>Reusing the same styles for HTML elements</h3><p>If you want to apply the same styles to the entire document, or for every &lt;h1&gt; or &lt;p&gt; tag, you don’t have to reuse the same code! Open your main.css file and add a base layer.</p><pre># main.css</pre><pre>@tailwind base;<br>@tailwind components;<br>@tailwind utilities;</pre><pre>@layer base {<br>  html {<br>    @apply smooth-scroll;<br>  }<br>  h1 {<br>    @apply text-3xl m-2 underline;<br>  }<br>  p {<br>    @apply m-2 text-gray-600 text-bold;<br>  }<br>}</pre><p>Let’s break down what’s happening above.</p><p>If you look at @layer base {} you can see some custom styles we’ve added. smooth-scroll will be applied to the entire html, and all &lt;h1&gt; and &lt;p&gt; tags will be given specific styles. With this syntax in place, you won’t have to add the same styles to <em>every</em> h1 and p tag.</p><p>However, you can add more styles to the individual tags, and it’ll override the base styles.</p><h3>Adding custom styles</h3><p>Sometimes you’ll want to add custom styles, for example a background-image or a custom break-point. To do this, lets open your tailwind.config.js file. To add custom break-points, add it to the extend object:</p><pre>...<br>extend: {<br>  screens: {<br>    xsm: &quot;425px&quot;,<br>    sm: &quot;480px&quot;,<br>    md: &quot;640px&quot;,<br>    tablet: &quot;768px&quot;,<br>    lg: &quot;1024px&quot;,<br>    xl: &quot;1280px&quot;,<br>  },<br>},</pre><p>Break-points and font-family are added to the extend object, but check the Tailwind CSS documentation to be sure.</p><p>Adding breakpoints and a new font family would look like this:</p><pre>...<br>extend: {<br>  screens: {<br>    xsm: &quot;425px&quot;,<br>    sm: &quot;480px&quot;,<br>    md: &quot;640px&quot;,<br>    tablet: &quot;768px&quot;,<br>    lg: &quot;1024px&quot;,<br>    xl: &quot;1280px&quot;,<br>  },<br>  fontFamily: {<br>    &quot;Merriweather&quot;: &quot;serif&quot;,<br>    &quot;Open Sans&quot;: &quot;sans-serrif&quot;,<br>  },<br>},</pre><p>After updating your tailwind.config.js file, you’ll likely need to run npm run build for the changes to take place (assuming you’re using React and npm).</p><h3>Media queries and break-points</h3><p>Break-points are what’s used for mobile-responsive design. For example, if you want the font size of a headline to be 32px on a mobile device, but 52px on desktop, you’d handle this by changing breakpoints.</p><p>With Tailwind CSS, the smallest size break-point is the default, and will carry its way up until the largest break-point size. For example, if you set padding on a div to be 16px, this property will apply on all screen sizes. This would look like this: &lt;div className=&quot;m-4&quot;&gt; .</p><p>Lets say you wanted padding to increase to 32px when screen size is 768px, and to 48px when screen size is 1024px. It’d look like this: &lt;div className=&quot;m-4 md:m-8 lg:m-12&gt; .</p><p>Note that Tailwind CSS has default breakpoints which you can see <a href="https://tailwindcss.com/docs/responsive-design#customizing-breakpoints">here</a>.</p><h3>Conclusion</h3><p>When starting out with Tailwind CSS, the syntax can feel verbose. It took me a few days to appreciate how good of a framework it is. With traditional CSS, if you have a bunch of similar elements, but 1 or 2 of them need a simple change, you’d have to make a new class in your stylesheet. This can get confusing, especially if you have hundreds of styles, and need to scroll through your stylesheet to locate a class.</p><p>Tailwind CSS is nice because all styles are directly on the element you’re styling. It makes it easier to locate things. This is similar to inline styles. <a href="https://tailwindcss.com/docs/utility-first#why-not-just-use-inline-styles">Read the documentation to see why Tailwind CSS is better than using inline styles</a>.</p><p>As with all my articles, leave a comment if you have any questions, or corrections to anything I’ve written.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1fdf26ee61c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Use Web3Modal In Next.js]]></title>
            <link>https://medium.com/@personnamedmike/how-to-use-web3modal-in-next-js-64af51789f5c?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/64af51789f5c</guid>
            <category><![CDATA[walletconnect]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[web3modal]]></category>
            <category><![CDATA[ethersjs]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 21:14:24 GMT</pubDate>
            <atom:updated>2022-07-18T21:19:31.872Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0b-g_-H_drtMRL0jXIA0Q.png" /><figcaption>Web3Modal makes it easy to connect your favorite wallet</figcaption></figure><p>This article is for you if you’ve tried using Web3Modal with WalletConnectProvider in your create-react-app project.</p><ul><li><a href="https://www.npmjs.com/package/web3modal">Web3Modal documentation</a></li><li><a href="https://www.npmjs.com/package/@walletconnect/web3-provider">WalletConnectProvider documentation</a></li></ul><p><strong>The problem:</strong></p><p>I tried to use Web3Modal with create-react-app . I kept running into breaking errors about how CRA v5 <em>used</em> to include polyfills for node.js core modules by default. I won’t go into more detail, but you can read more about it in this <a href="https://github.com/facebook/create-react-app/issues/11756">github thread</a> if you’re interested.</p><p>I heard that using Web3Modal in Next.js wouldn’t cause similar issues. I decided to ditch CRA and switch over to Next.js. Next renders code server-side, not client-side. This means that you don’t have access to the JavaScript window object in your JSX components.</p><p><strong>My Solution</strong>:</p><p>One way to get around the issue of Next.js not having a window object, is by utilizing a useEffect hook, along with useState. Code written in a useEffect hook will render only after the component has rendered in the client.</p><pre>// code<br><em>const</em> [web3Modal, setWeb3Modal] = useState({});</pre><pre>useEffect(() =&gt; {<br>   if (typeof window !== &quot;undefined&quot;) {<br>      <em>const</em> web3modal = new <strong>Web3Modal</strong>({<br>       network: &quot;rinkeby&quot;, <em>// optional<br>       </em>cacheProvider: true, <em>// optional<br>       </em>providerOptions, <em>// required<br>      </em>});<br>      setWeb3Modal(web3modal);<br>   }<br>}, []);</pre><p>In the code above, we render a new Web3Modal object in a useEffect hook, then store that object into state with the setWeb3Modal setter function and useState hook.</p><p>Now that we have Web3Modal saved into state, we can use that object when using WalletConnectProvider with our app. Here’s the rest of the code, which goes within our component function, but before we return any JSX:</p><pre><em>const</em> providerOptions = {<br>   walletconnect: {<br>      package: WalletConnectProvider, <em>// required<br>      </em>options: {<br>         infuraId: process.env.REACT_APP_INFURA_ID, <em>// required<br>      </em>},<br>   },<br>};</pre><pre><em>const</em> connect = <em>async</em> () =&gt; {<br>   try {<br>      <em>const</em> instance = await web3Modal.connect();<br>      <em>const</em> provider = new ethers.providers.Web3Provider(instance);<br>      <em>const</em> signer = provider.getSigner();<br>      <em>const</em> accounts = await provider.listAccounts();<br>      setUserAccount(account.current);<br>   } catch (err) {<br>     console.log(err);<br>   }<br>};</pre><p>This solution allowed for Web3Modal to work in Next.js project. Please comment on anything that can be improved, and good luck with your projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64af51789f5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the React useRef Hook]]></title>
            <link>https://medium.com/@personnamedmike/what-is-the-react-useref-hook-6fa2eae233ec?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fa2eae233ec</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[useref]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Sun, 03 Jul 2022 15:40:23 GMT</pubDate>
            <atom:updated>2022-07-03T15:40:23.125Z</atom:updated>
            <content:encoded><![CDATA[<p>useRef is a <a href="https://reactjs.org/docs/hooks-intro.html">React hook</a> that lets you keep track of data, even when a component re-renders. The major difference between useRef and useState, is that changing state in a useState hook will trigger all components to re-render, and useRef will not.</p><p>It’s helpful to think of useRef like an instance variable that you can change, but a component re-render will not cause it to change.</p><h3>How to use a useRef hook:</h3><p>First, you must import it from React: import { <strong>useRef</strong> } from &quot;react&quot;</p><p>Next, create an instance: const countRef = useRef(0);</p><p>A useRef instance gives you access to an object with exactly 1 key, called current. Looking at the example above:</p><pre>countRef = { current: 0 }</pre><p>To increment countRef by 1, you can access the object:</p><pre>countRef.current +=1;</pre><p>This would not cause components to re-render, like if you were to hold countRef in a useState variable instead.</p><h3>Accessing DOM elements with useRef</h3><p>One of the major use cases for the useRef hook is if you need to directly access a DOM element. For example, you might want to capture the dimensions and position of a div.</p><pre>import react, { useRef } from &quot;react&quot;;</pre><pre>const Dimensions() {<br>   const measurementRef = useRef();</pre><pre>   return (<br>      &lt;div <strong>ref</strong>={measurementRef}&gt;example&lt;/div&gt;<br>   )<br>};</pre><p>By including the <strong>ref</strong> tag within the div, that div’s properties will be saved into measurementRef . Now you can access all of its properties, for example, measurementRef.getBoundingClientRect() will return various properties of the referenced div.</p><p>Other use cases for useRef are giving 3rd party libraries access to DOM elements, as well as giving HTML canvas, video, or audio elements access to DOM nodes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fa2eae233ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Hackathon Experience at ETH New York]]></title>
            <link>https://medium.com/@personnamedmike/my-first-hackathon-experience-at-eth-new-york-7e64b3c8454b?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e64b3c8454b</guid>
            <category><![CDATA[ethglobal]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[ethnewyork]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[hackathons]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Tue, 28 Jun 2022 02:06:33 GMT</pubDate>
            <atom:updated>2022-09-08T15:27:47.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y4FEzUrYNTGy0MnWq7jX-Q.jpeg" /><figcaption><a href="https://worldcoin.org/">Worldcoin</a> Orb 🧐</figcaption></figure><p>Hackathons are exciting, challenging, educational, and great for meeting like-minded people and companies. Hackers have a chance to win cash prizes, and sponsors have the chance to fund the next big project and grow their ecosystem.</p><p><strong>This post will be broken into 3 main sections:</strong></p><ol><li><a href="https://medium.com/@personnamedmike/my-first-hackathon-experience-at-eth-new-york-7e64b3c8454b/#848a">My non-technical experience at the conference</a></li><li><a href="https://medium.com/@personnamedmike/my-first-hackathon-experience-at-eth-new-york-7e64b3c8454b/#dd45">Project overview</a></li><li><a href="https://medium.com/@personnamedmike/my-first-hackathon-experience-at-eth-new-york-7e64b3c8454b#a20c">Lessons learned</a></li></ol><h3>My conference experience (non-technical)</h3><p>This past weekend wrapped up ETH New York. This was a 3 day in-person hackathon hosted by <a href="https://medium.com/u/3d1733b8e86a">ETHGlobal</a>. About 1500 hackers attended, and about 40 companies sponsored the event. All sponsoring projects were built on Ethereum, and hackers were expected to build on Ethereum as well.</p><p>The event took place in a massive venue in downtown Manhattan. <a href="https://medium.com/u/3d1733b8e86a">ETHGlobal</a> graciously provided free food, drinks and coffee. The energy was electric (pun intended). There were also guest speakers, including Hayden Adams from Uniswap, and Karl Floersch from Optimism.</p><p>I signed up for this hackathon because I heard that hackathons were a great way to learn, meet people in the industry, and expose your weak points.</p><p>Several weeks prior, I participated in ETH Global’s HackMoney event. This was an online-only hackathon which lasted a few weeks. I wasn’t able to find a teammate for HackMoney, so I worked on a small project by myself. Attending an event in person was a better experience all around.</p><p>This time I was able to find a teammate. A recruiter introduced me to her over Twitter. We met for the first time in person at the event, and became friends right away.</p><p><strong>Day 1</strong> of the event started at 2pm on a Friday. We weren’t allowed to start building until 7pm, so my teammate and I just brainstormed that day. My brain power deteriorates at night, so we decided not to start coding until the next morning.</p><p><strong>Day 2</strong>, I arrived at the venue around 8am, and got to work. I worked on the frontend (I’ll go into the nitty-gritty in the <a href="http://dd45/">project overview</a> section of this post). My partner worked on the smart contract.</p><p>We were making nice progress, but around 9pm we ran into bugs that completely broke our app. We troubleshooted until 11pm, but weren’t able to resolve it in time. My partner and I were both exhausted, so we called it a night.</p><p>Sadly, project submissions were due by 9am the next day. We wouldn’t have enough time to fix the bugs and present to the judges</p><p><strong>Day 3, </strong>I woke up at 7:30am, submitted what we had, and went to the event space. It was disappointing having nothing to present, but it was exciting watching others showing off their projects. The vibes were huge, and people were proud of their efforts.</p><p>Around 2:30pm, the finalists presented their projects to the audience. It was impressive what some of these people were able to build in only 36 hours! After the presentations there was a happy hour, and the event officially ended by 7pm.</p><h3>Project overview</h3><p>Originally we wanted to build a social media platform, but after realizing our time constraints (and lack of manpower), we decided to simplify our project.</p><p>Our new idea was to build an app where users could upload a file, store it to IPFS using NFT.storage, then sell their NFT’s directly on the app. Nothing too complicated, but my main goal was to gain experience using new technologies.</p><p>Here’s the technology I used for the frontend:</p><ul><li>React (create-react-app)</li><li>Tailwindcss</li><li>React-router</li><li>Web3Modal, with provider options set to WalletConnect</li><li>Ethers.js</li></ul><p>I was able to build a basic UI with React, setup Web3Modal with WalletConnect as a provider, and have it connect to Polygon Mumbai testnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vm1cXeU08CEpVrgfGbLCqA.png" /><figcaption>Screenshot of the UI before things broke…</figcaption></figure><h3>Lessons Learned</h3><p>I learned a lot of hard lessons during this event, but I also improved my technical abilities. Here’s a list:</p><ul><li><strong>Tailwindcss:</strong> this was my first time using tailwindcss. I like how their documentation has visuals like <a href="https://tailwindcss.com/docs/flex-direction">this</a>. The syntax is a bit verbose, but perhaps I’ll get used to it</li><li><strong>Web3Modal:</strong> this was also my first time using Web3Modal. We used WalletConnect as a provider</li><li><strong>React:</strong> Currently React / JavaScript is my main skillset, but it’s always good to get more practice using it</li><li><strong>Webpack: </strong>This was the first time I’ve dealt with Webpack issues. We believe these issues were caused from some of the Web3 npm packages. The main thing I learned is that you need to be able to troubleshoot Webpack if you want to develop frontends for web3 apps with React. In the future I’ll write a post about Webpack</li><li><strong>Sometimes you need a different framework for a given task:</strong> As I’m still troubleshooting issues faced during the hackathon, my teammate suggested that using Next.js will likely resolve the problems we were facing. I used create-react-app , which seems to cause issues with a lot of web3 npm packages</li><li><strong>Commit to GitHub more often:</strong> When working on a project, I usually commit to GitHub often. In the future I’ll commit even more. This possibly would have made it easy to troubleshoot Webpack, as I could have isolated the issue more easily</li><li><a href="https://medium.com/@personnamedmike/how-to-hide-your-api-keys-using-node-js-9e51d10fc9d0"><strong>Dotenv</strong></a><strong>:</strong> I setup a .env file, added it to my gitignore file, and tested it to make sure my Infura API keys were hidden. Somehow a file was created which exposed my API keys on GitHub. I had a credit card on file with my Infura account, so I immediately deleted the repo and deactivated my Infura account. In the future I’ll use Alchemy, or a provider who doesn’t require a credit card</li><li><strong>Plan more before my next hackathon</strong>: I was grateful to actually have a team member this time (I wasn’t able to find anyone the first time), but I wish we had spent more time planning our project before the event started</li><li><strong>Stay closer to the venue, or bring a sleeping bag and air mattress</strong>: I had to travel 1 hour each way to get to the venue. Next time I’ll bring supplies in case I want to spend the night at the event</li><li><strong>Hackathons are GREAT for networking</strong>: As a newcomer to web3, one of my goals at this event was to meet people in the industry and make friends. I met some friendly people who gave me fantastic advice about building in web3, and getting a job. I’d say this was the most valuable aspect of the event for me</li><li><strong>Twitter is a great communication tool in the web3 space: </strong>It’s ironic that a web2 platform is used so much for web3, but connections are made, and maintained on web2 social media. Can we get web3 social media up to speed please?!</li></ul><h3><strong>Conclusion</strong></h3><p>ETH New York was a great experience and many people gained a lot of value. Huge thanks to the <a href="https://medium.com/u/3d1733b8e86a">ETHGlobal</a> team for organizing this, and I cannot wait for the next one! Perhaps ETH Bogota in October? I’ll likely do at least 1 more virtual hackathon before then.</p><p>In the meantime, I’m currently working on finishing up my project that I wasn’t able to present to the judges at ETH New York. My teammate and I are disappointed about this, but the experience and connections I made is more valuable than any amount of cash prize we could have won.</p><p>I’m happy about my own experience at the event, but the most encouraging part about it was seeing how many people attended. Currently the crypto market (and macro in general) is quite bearish, but the excitement and passion people had at this event makes me bullish on the future of the space!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e64b3c8454b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Hide Your API Keys When Committing To Github]]></title>
            <link>https://medium.com/@personnamedmike/how-to-hide-your-api-keys-using-node-js-9e51d10fc9d0?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e51d10fc9d0</guid>
            <category><![CDATA[dotenv]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[env]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Wed, 11 May 2022 18:29:27 GMT</pubDate>
            <atom:updated>2022-05-15T05:45:21.348Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*OJzHfQVTUUNPuU7ggmdu5Q.jpeg" /></figure><p>Private keys are sensitive information. Some bots exist with the purpose of scraping API keys from Github. I’ve heard horror stories of people having their API keys stolen, and <a href="https://medium.com/@morgannegagne/a-very-expensive-aws-mistake-56a3334ed9ad">being billed for over $7,000</a>.</p><p>One accidental commit to Github, and your private keys are now open source, and available for anyone to steal. Be careful.</p><p>Here’s a checklist of how you can keep sensitive information safe from prying eyes.</p><ol><li>Create a <strong>.gitignore</strong> file in the root directory of your project. This can be created when you initialize a new git repository</li><li>In your project’s root directory, create a file called <strong>.env</strong></li><li>Make sure to include <strong>.env </strong>in your <strong>.gitignore</strong> file</li><li>In your <strong>.env</strong> file, include your API keys and any other sensitive information you need in your app. Be sure to save each piece of data to a variable. For example: <strong>API_KEY=“798759034790543”</strong></li><li>Run the following command to install dotenv: <strong>npm install dotenv</strong></li><li>Add the following code to the top of your file which needs the API key: <strong>require(“dotenv”).config();</strong></li><li>Test out that dotenv is working by console logging the object: <strong>console.log(process.env)</strong>. If working correctly, this should include variables that you saved into your <strong>.env</strong> file</li><li>Wherever you need to access your API key, you can use the following code: <strong>process.env.API_KEY</strong>. (You can replace API_KEY with any variable you’ve declared in your .env file)</li></ol><p>Now if you run <strong>git add . </strong>and <strong>git status</strong>, you should not see your <strong>.env</strong> file and its sensitive information being staged for a commit.</p><p>Keep in mind that the above steps should work to keep your API keys safe on your front end. There might be additional steps you can take to keep your back end secure as well, but that’s beyond the scope of this article.</p><p><strong>Note if using dotenv with React</strong></p><p>If you’re building with React, all variables in your .env file must begin with <strong>REACT_APP_. </strong>React has built in functionality for dotenv which won’t allow it to work otherwise.</p><p>For example, your API key key should be declared in your .env file as such: <strong>REACT_APP_API_KEY=“798759034790543”</strong>. <strong>API_KEY=“798759034790543”</strong> will not work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e51d10fc9d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Router — A Basic Guide]]></title>
            <link>https://medium.com/@personnamedmike/react-router-a-basic-guide-1790029462f4?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1790029462f4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-router]]></category>
            <category><![CDATA[software-engineer]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Mon, 18 Apr 2022 14:11:42 GMT</pubDate>
            <atom:updated>2022-04-18T14:11:42.458Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Router — A Basic Guide</h3><figure><img alt="React Router logo" src="https://cdn-images-1.medium.com/max/698/1*TKvlTeNqtkp1s-eVB5Hrvg.png" /></figure><p>React Router is a JavaScript library for React. It allows you to create routes and direct users to specific URL paths. This creates a more seamless user experience, especially for single page React applications.</p><p>This article will reference v6, the latest release of React Router at the time of this writing. We’ll cover the following concepts: configuring routes, navigating with Link, NavLink, programmatic navigation, and using URL search params. Tags include:</p><pre>&lt;BrowserRouter&gt;, &lt;Routes&gt;, &lt;Route&gt;, &lt;Link&gt;, &lt;NavLink&gt;, useParams(), useNavigate()</pre><h3>Step 1: Install React Router in your app directory</h3><p>Add React Router to your package.json. Choose your preferred package manager:</p><pre>// npm<br><strong>$ npm install react-router-dom@6</strong></pre><pre>// yarn<br><strong>$ yarn add react-router-dom@6</strong></pre><pre>// pnpm:<br><strong>$ pnpm add react-router-dom@6</strong></pre><h3>Wrap your entire app in &lt;BrowserRouter&gt;</h3><p>&lt;BrowserRouter&gt; is a tag which must wrap around your entire application. It’s only needed once, and likely should be placed into your index.js file, which gets created if you use create-react-app</p><pre>import React from &quot;react&quot;;<br><strong>import { BrowserRouter } from &quot;react-router-dom&quot;;</strong><br>import App from &quot;./App&quot;;<br><br>ReactDOM.render(<br><strong>  &lt;BrowserRouter&gt;</strong><br>    &lt;App /&gt;<br><strong>  &lt;/BrowserRouter&gt;,</strong><br>  document.getElementById(&quot;root&quot;)<br>);</pre><p>The App.js component is wrapped in &lt;BrowserRouter&gt; tags. { BrowserRouter } gets imported from react-router-dom to the top of your file.</p><h3>Configuring routes:</h3><p>Now that we’ve setup React Router, let’s create some basic routes! For simplicity sake, we’ll create routes on the App level. Wherever you create your routes is the component where your routes will be rendered from</p><pre>import React from &quot;react&quot;;<br>import { <strong>Routes</strong>, <strong>Route</strong> } from &quot;react-router-dom&quot;;<br>import Header from &quot;./Header&quot;;<br>import Shoes from &quot;./Shoes&quot;;</pre><pre>function App() {<br>  return (<br>    &lt;&gt;<br>      &lt;Header /&gt;<br>      &lt;h1&gt;My Shoe Store&lt;/h1&gt;<br>        <strong>&lt;Routes&gt;</strong><br>          &lt;<strong>Route</strong> path = &quot;/&quot; element={&lt;Home /&gt;} /&gt;<br>          &lt;<strong>Route</strong> path = &quot;/shoes&quot; element={&lt;Shoes /&gt;} /&gt;<br><strong>        &lt;/Routes&gt;<br>    </strong>&lt;/&gt;<br>  );<br>}</pre><p><strong>&lt;Route&gt;</strong> and self-closing tags that must be wrapped in opening and closing <strong>&lt;Routes&gt;</strong> tags.</p><p><em>(Older versions of React Router may have used the &lt;Switch&gt; tag instead of &lt;Routes&gt;, but as of v6, this is now deprecated).</em></p><p>Now that your routes have been established in the App level, when a user navigates to these routes, these components will render along with the rest of the App.js component. As per the example above, if a user gets routed to the <strong>“/shoes”</strong> route, the App.js component will render along with the Header.js component and &lt;h1&gt; tags.</p><p>Now that your routes have been established, there are several ways to allow users to navigate to these routes.</p><h3>Navigating with Link</h3><p>To link to a route that has been declared within &lt;Routes&gt; and &lt;Route&gt; tags, one way is to use <strong>&lt;Link&gt;</strong> tags. The example code below will build upon the code we used in the example above.</p><pre>import React from &quot;react&quot;;<br>import { <strong>Link</strong> } from &quot;react-router-dom&quot;;</pre><pre>function Display() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Shoe Display&lt;/h2&gt;<br>      &lt;<strong>Link</strong> to &quot;/shoes&quot;&gt;Shoes&lt;/Link&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><p>The code above would insert a link with the text of “<em>Shoes”</em> into the Display.js component. We already established the “shoes” route, which links to the Shoes.js component at the path of <em>/shoes</em>. Clicking on this link in the Display.js component would route you to that path, and the URL in your browser would point to the path of /shoes.</p><h3>NavLink (just like Link, but for Nav bars)</h3><p>NavLink is similar to Link, but with one key difference — NavLink lets you apply an active class to links. This might be useful for a navigation bar, as you can apply styles to an active link, which lets users more easily see which page they’re currently on. This can also be useful for assistive technology like screen readers.</p><p>An <em>active</em> class is built into &lt;NavLink&gt;. The code below was mostly taken from the official <a href="https://reactrouterdotcom.fly.dev/docs/en/v6/api#navlink">documentation</a>:</p><pre>import { <strong>NavLink</strong> } from &quot;react-router-dom&quot;;</pre><pre>function NavBar() {<br>  let <strong>activeStyle</strong> = {<br>    textDecoration: &quot;underline&quot;,<br>    color: &quot;blue&quot;,<br>  };</pre><pre>  let <strong>activeClassName</strong> = &quot;unerline&quot;;</pre><pre>  return (<br>    &lt;nav&gt;<br>      &lt;<strong>NavLink</strong> to=&quot;shoes&quot; <strong>style</strong>={({ isActive }) =&gt;<br>        isActive ? activeStyle : undefined<br>      }<br>      &gt;<br>      &lt;/<strong>NavLink</strong>&gt;<br>  )<br>};</pre><p>NavLink has a built in class called <strong>isActive. </strong>We pass a ternary statement into NavLink. If a user is on a route that they were brought to from a NavLink, <strong>isActive</strong> will be set to true, and the style class of <strong>activeStyle</strong> will be applied</p><h3>Passing Props Into Routes</h3><p>You can pass props into routes. As an example, let’s go back to our App.js component and change one of our routes so it accepts props:</p><pre>// App.js component<br>&lt;<strong>Route</strong> path = &quot;/shoes&quot; element={&lt;Shoes brand={brand}/&gt;} /&gt;</pre><p>Now whenever a user navigates to the <em>shoes</em> path, the “brands” prop will get passed in from the App.js component down to the Shoes.js component.</p><h3>Navigation with the useNavigate Hook</h3><p>This hook lets you programmatically navigate to another route, and is often used in an event handler.</p><pre>let <strong>navigate</strong> = <strong>useNavigate()</strong>;</pre><pre>function createAccount(e) {<br>  e.preventDefault();<br>  <strong>navigate</strong>(&quot;/create-account&quot;);</pre><pre>&lt;button onClick={createAccount}&gt;Create Account&lt;/button&gt;</pre><p>First we declare an variable called <strong>navigate</strong>, and set it equal to an instance of useNavigate(). Next, we use this instance to navigate to our desired route, which in this case is the route /create-account.</p><p>useNavigate() can also be used to navigate history. The following code will allow users to navigate back in history 1 page:</p><pre>let navigate = useNavigate<br>// ... code</pre><pre><strong>navigate(-1)</strong></pre><p>Passing in -2 to navigate() will move the user back 2 pages in history.</p><h3>Programmatic Navigation with useParams</h3><p>When creating a route using the &lt;Route&gt; tag, you can create a dynamic route. The syntax for this is to put a colon in front of the route name. For example:</p><pre>&lt;Route path=&quot;users/<strong>:id</strong> element={&lt;UserProfile /&gt;} /&gt;</pre><p>With this route in place, if you land on the page http://localhost:4000/users/15, the dynamic route of <strong>:id </strong>will capture an id of <strong>15.</strong> You can access this id with the useParams hook.</p><pre>let params = useParams();</pre><p>With this instance of the useParams hook in place in the UserProfile.js, you can access the dynamic variable which was passed in. Params returns a key-value object with all the parameters that were dynamically passed into the route.</p><p>If a user visits http://localhost:4000/users/15, then <strong>params.id</strong> variable will equal 15.</p><p>A second example:</p><pre>&lt;Route path=&quot;users/<strong>:id</strong>/<strong>:name</strong> element={&lt;UserProfile /&gt;} /&gt;</pre><p>In this example, if you visit the following path: http://localhost:4000/users/15/john, then accessing <strong>params</strong> will return the following:</p><pre>// UserProfile.js</pre><pre>//...<br>console.log(<strong>params</strong>)<br>// { id:15, name:john }</pre><pre>console.log(<strong>params.id</strong>)<br>// 15</pre><pre>console.log(<strong>params.name</strong>)<br>// john</pre><h3>Conclusion</h3><p>This was a basic overview of some of the basic React Router functionality. In my experience, it takes some practice to get used to, but allows for more dynamic, robust UIs. As always, consult the documentation if my explanation isn’t clear enough, or if you want to take a deeper dive. <a href="https://reactrouterdotcom.fly.dev/docs/en/v6">https://reactrouterdotcom.fly.dev/docs/en/v6</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1790029462f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Styled-Components — a Basic Guide]]></title>
            <link>https://medium.com/@personnamedmike/react-styled-components-a-basic-guide-2e03c7bbbfcd?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e03c7bbbfcd</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[styled-components]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Thu, 07 Apr 2022 18:02:07 GMT</pubDate>
            <atom:updated>2022-04-07T21:37:48.570Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Styled-Components — a Basic Guide</h3><figure><img alt="Styled-components logo" src="https://cdn-images-1.medium.com/max/225/1*r9IqHXoe4jODuiwakSNJpQ.png" /></figure><p>Styled-components is a library for React. It allows you to create components, within a React component, that are responsible for handling CSS styles. Styled components aligns with the React philosophy of isolating functionality. It can keep your code more organized, which might reduce the amount of bugs you encounter.</p><p>You can read the documentation here: <a href="https://styled-components.com/docs"><em>styled-components documentation</em></a><em>.</em></p><h3>Getting Started</h3><p>In a terminal window, cd into your project directory. If using npm, enter this command:</p><pre># if using npm:<br><strong>npm install — save styled-components</strong></pre><pre># if using yarn:<br><strong>yarn add styled-components</strong></pre><p>In package.json, add this code:</p><pre>{<br>   &quot;resolutions&quot;: {<br>   &quot;styled-components&quot;: &quot;^5&quot;<br>   }<br>}</pre><h3>Basic Syntax</h3><p>At the top of your components that will use the library, add the following:</p><pre>import styled from “styled-components”;</pre><p>Below is an example. You’d insert this code within a component function, and above its JSX:</p><pre>const Title = <strong>styled</strong>.h1`<br>   color: blue;<br>   margin-top: 1em;<br>`;</pre><ul><li>Declare a const variable with an uppercase (e.g. Title).</li><li><strong>styled</strong> refers to the class which was imported from the “styled-component” library</li><li><strong>h1</strong> can be any HTML selector you want to want to style</li><li>`Backticks` are used after the HTML selector, and enclose the CSS styles</li></ul><pre>import React, { useState } from &quot;react&quot;;<br>import <strong>styled</strong> from &quot;styled-components&quot;;</pre><pre>const <strong>Title</strong> = <strong>styled</strong>.h1`<br>   color: blue;<br>   margin-top: 1em;<br>`;</pre><pre>function Post() {<br>   return (<br>    &lt;&gt;<br>     <strong>&lt;Title&gt;</strong>Your Title Here<strong>&lt;/Title&gt;<br>    </strong>&lt;&gt;<br>   )<br>}</pre><p>After creating the Title styled component, you can now wrap any JSX with opening and closing tags of that component, and styles will be applied to it. This is done in contrast to wrapping JSX in tags that contain HTML elements and ClassName=“ ”.</p><p>Without styled components, the above example would look like the example below. className=“title” would be pointing to an external CSS stylesheet, instead of a styled-component:</p><pre>import React, { useState } from &quot;react&quot;;</pre><pre>function Post() {<br>   return (<br>     &lt;&gt;<br>      <strong>&lt;h1 className=&quot;title&quot;&gt;</strong>Your Title Here<strong>&lt;/h1&gt;<br>     </strong>&lt;&gt;<br>   )<br>}</pre><h3>Adding pseudo-classes to a styled component</h3><p>Pseudo-classes are used to define a special state of an element. For example, when you hover over an element, or when a link has been visited or unvisited</p><p>Syntax:</p><pre>const Title = <strong>styled</strong>.h1`<br>   color: blue;<br>   margin-top: 1em;</pre><pre>   <strong>&amp;:hover {<br>      </strong>color: green;<br>   <strong>}<br></strong>`;</pre><p>Within the backticks of your styled component, use an ampersand and colon, <strong>&amp;:</strong>, to define a pseudo-class. Styled-components usesthe ampersand to reference to the element currently being styled. In the example above, the hover pseudo-class will cause any JSX elements wrapped in &lt;Title&gt; &lt;/Title&gt; components to take on its styles.</p><h3>Global styles</h3><p>Global styles are used to apply styles to every element within a document, not only a specific component. The styled-components library has a built in helper for this called <strong>createGlobalStyle</strong>.</p><p>First you should create a new file within your /src folder called globalStyles.js Here’s the syntax for this file:</p><pre>import { <strong>createGlobalStyle</strong> } from “styled-components”;</pre><pre>const GlobalStyle = <strong>createGlobalStyle</strong>`<br>   body {<br>      font-family: ‘Arial&#39;<br>   }</pre><pre>   a {<br>      color: blue<br>   }</pre><pre>   p {<br>      margin: auto<br>   }<br>`;</pre><pre>export default GlobalStyle</pre><p>The above global style sheet will apply styles to the body, anchor tags and paragraphs.</p><p>Next, you’ll need to import this file to your main App.js component (or whatever you’ve named the main component in your project). To have these styles render, insert a self-closing tag to the top of your App.js JSX:</p><pre>function App() {<br>   return (<br>      &lt;&gt;<br>        <strong>&lt;GlobalStyle /&gt;</strong><br>      &lt;&gt;<br>   )<br>}</pre><p>Using <strong>createGlobalStyles</strong> is more robust than a regular global CSS file. This is because it allows you to make use of props, which can be useful for things such as toggling between a light/dark mode.</p><h3>Props and styled components</h3><p>A reason to use props with styled components is if you want to conditionally render some CSS styling. For example, let’s say you’re mapping over an object, and rendering each item into it’s own &lt;ListItem&gt; component. You might want to alternate colors of each row, so that even numbered rows are black, and odd numbers are yellow.</p><p>To do this, you can make use of props. The syntax for this is to pass a callback function into a styled component’s template literal (what goes within backticks), and to return a ternary statement in the function.</p><pre>const ListItem = styled.li`<br>   padding: 1em;<br>   background: ${props =&gt; props.<strong>isEven</strong> ? &#39;black&#39; : &#39;yellow&#39;};<br>   color: white<br>`</pre><pre>List() {<br>   return (<br>      &lt;UnorderedList&gt;<br>         {items.map((item, index) =&gt; {<br>            &lt;ListItem key={item} <strong>isEven</strong>={(index + 1) % 2 === 0} /&gt;<br>               {item}<br>            &lt;/ListItem&gt;<br>         ))}<br>      &lt;/UnorderedList&gt;<br>   );<br>}</pre><p>Let’s breakdown this code.</p><p>The ListItem component has a prop called <strong>isEven</strong>. This has some logic built in, which determines if it’s equal to an odd or an even number. An even number returns a truthy value, an odd number returns falsy.</p><p>In the JSX, an object called <em>items</em> is being mapped over, which will determine the values rendered in the logic passed into the <strong>isEven</strong> prop.</p><p>Now looking at the ListItem styled component, we have some conditional logic within the <strong>background</strong> attribute. Different conditions will be rendered, depending on the values calculated from within the <strong>isEven</strong> prop.</p><h3>Overwriting existing styles</h3><p>Sometimes you need to overwrite existing styles. For example, if you’re using a framework like Bootstrap, and need to change something. To do this, you can wrap the existing style:</p><pre>const StyledButton = <strong>styled</strong>(Button)`<br>   &amp;&amp; {<br>   color: &#39;red&#39;:<br>   }<br>`;</pre><p>Button already has styles, but we’ve wrapped it with the <strong>styled</strong> class. In the above example, this would override existing styles in the <em>Button</em> component with our styles declared in the StyledButton component.</p><p>The reason we use 2 ampersands is because specificity matters. Sometimes an existing class, such as that from Bootstrap, might have a lot of specificity. Using &amp;&amp; applies the style to the component twice, and this is often enough to override what already exists in the class being overridden.</p><h3><em>“as”</em> keyword</h3><p>In regular CSS stylesheets you can directly apply the same styles to multiple selectors. This is done by separating each selector with comments. For example:</p><pre>h1,h3,p {<br>   color: blue;<br>}</pre><p>This cannot be done with styled-components, but there’s a workaround. You can use the “<strong><em>as</em></strong><em>”</em> keyword to dynamically swap out the element that received the styles you wrote.</p><pre>const Button = styled.button`<br>   background: &#39;black&#39;;<br>   color: &#39;yellow&#39;;<br>   border-radius: 10px;<br>`</pre><pre>function post() {<br>   &lt;div&gt;<br>      &lt;Button <strong>as</strong>=&quot;a&quot; href=&quot;/home&quot;&gt;Home&lt;/Button&gt;<br>   &lt;/div&gt;<br>}</pre><p>In the above example, we have a styled component called Button. We applied these styles to a regular anchor tag by using the <strong>as</strong> keyword.</p><h3>Conclusion</h3><p>Styled-components is a React library that allows you to create JavaScript components that are responsible for CSS styling. It’s a great way to keep your code DRY, and organized. Be sure to read the official documentation for a better understanding of what was covered in this article.</p><p><a href="https://styled-components.com/docs">https://styled-components.com/docs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e03c7bbbfcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Oriented Programming in Ruby — A Basic Guide]]></title>
            <link>https://medium.com/@personnamedmike/object-oriented-programming-in-ruby-a-basic-guide-37927197e796?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/37927197e796</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Wed, 23 Mar 2022 20:02:36 GMT</pubDate>
            <atom:updated>2022-03-23T22:53:50.132Z</atom:updated>
            <content:encoded><![CDATA[<h3>Object Oriented Programming in Ruby — A Basic Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*xDBKglGKbvvUNr5F9kGT0Q.png" /></figure><p>(This post will refer to object-oriented programming as OOP)</p><h3><strong>What is Object-Oriented Programming?</strong></h3><p>OOP is computer programming model that’s structured around objects which contain data, rather than functions or logic. It is class-based, which means that a class defines the data attributes and function. A class is like a blueprint that can be used to create an instance, or a clone of itself.</p><p>A common use-case for classes is database creation. A new entry (row) in a database is basically an instance of a class. Data entered into a database must be uniform, which is why one reason why a blueprint can be useful.</p><p>This article will focus on Ruby, but other popular OOP languages are: Python, Java, C#, and PHP.</p><h3><strong>Classes</strong></h3><p>A class is a template from which individual objects can be created. Classes can contain variables, and different types of methods.</p><p>Methods are functions that can be performed on internal data.</p><p>Syntax for creating a class:</p><pre>class Car<br><em>   # enter variables and methods here<br></em>end</pre><p>Classes must be declared with the word <em>class</em>, and end with the keyword <em>end</em>. Class names (in this example, Car), must be declared in uppercase.</p><p>Syntax for creating an instance of a class:</p><pre>car1 = Car.new</pre><p>In the above example, a new instance of the Car class is saved to the variable car1. Adding the <strong>.new</strong> method after the class name creates the instance</p><p>When you create a new class, Ruby will return a hash value that looks like this: <strong>#&lt;Car:0x00007f8bec30fdc0&gt;</strong> . This syntax is called <em>Ruby Object Notation. </em>It’s a unique object identifier that’s used to temporarily save the object into memory on your computer.</p><p>Every new instance of a class will have its own unique identifier.</p><pre>car1 = Car.new<br>=&gt; <strong>#&lt;Car:0x00007f8bec30fdc0&gt;</strong></pre><pre>car2 = Car.new<br>=&gt; <strong>#&lt;Car:0x00007f8bec1bcdb0&gt;</strong></pre><p>Calling <em>car1</em> in a REPL, such as PRY or IRB, will return the same identifier as when it was created:</p><pre>car1<br>=&gt; <strong>#&lt;Car:0x00007f8bec30fdc0&gt;</strong></pre><p><strong>Syntax</strong>: class names must start with an uppercase letter. For example:</p><pre>class Car<br>end</pre><pre><em># Ruby will throw an error if lowercase is used</em><br>class car<br>end</pre><p>Declaring a class name with a lower case letter will cause Ruby to throw an error. Note that you can use the same name for an instance method as a class</p><pre>class <strong>Car</strong><br>   def <strong>car</strong><br>      puts &quot;this is an instance method&quot;<br>   end<br>end</pre><pre><em># Ruby recognizes the class name </em><strong><em>Car</em></strong><em> as being different than the </em><strong><em>c</em></strong><em>ar instance method name</em></pre><h3>Instance Methods</h3><p>Instance methods are functions that can be called on an instance of a class. When you write code for an instance method, the code will go within a class. Every instance of a class will inherit its instance methods.</p><pre>class Car<br>   <em>#def car is a declaration of the instance method toyota:</em><br>   def toyota<br>      “I drive a Toyota.”<br>   end<br>end</pre><p>Using the example above, if you create an instance of the <em>car</em> class, then call the <em>toyota</em> instance method on that instance, this will be the result:</p><pre>car1 = Car.new<br>car1.toyota<br>=&gt; &quot;I drive a Toyota.&quot;</pre><p>Instance methods can be called with <strong>dot notation</strong>. The syntax for this is using a dot before the name of the method:</p><pre>class_intance.instance_method</pre><h3>Instance Variables</h3><p>An instance variable is accessible to every instance of a class. They’re built into class templates, and might output different results for different instances of a class.</p><p>Instance variables are declared with the syntax of @variable.</p><pre>class Car<br>   def model=(model_name)<br>      <strong>@car_model</strong> = model_name<br>   end</pre><pre>   def name<br>      <strong>@car_model</strong><br>   end<br>end</pre><p>Every instance of the Car class will inherit both of these <em>setter</em> and <em>getter</em> methods.</p><h3><strong>Setter and Getter Methods</strong></h3><p><strong>Setter methods</strong> are used in Ruby to <em>set attributes</em> on instances of a class. Setter methods take in an argument, and set an instance variable equal to that value. Let’s revisit our example from above:</p><pre><strong>def model=(model_name)</strong><br>   @car_model = model_name<br>end</pre><p>This setter method accepts a variable <em>model_name. </em>It then sets the instance variable <em>@car_model</em> to be equal to this argument<em> model_name</em>.</p><p><strong>Getter methods</strong> are used to “get” the values of the variables we set with a setter method</p><pre>class Car<br><em>   # setter method</em><br>   def model=(model_name)<br>      @car_model = model_name<br>   end</pre><pre><em>   # getter method</em><br>   <strong>def model</strong><br>      @car_model<br>   end<br>end</pre><pre>my_toyota = Car.new<br>my_toyota.model=&quot;Rav4&quot;</pre><pre>my_toyota.model<br>=&gt; &quot;Rav4&quot;</pre><p>In the above example we created a new instance of the Car class called my_toyota. We then called the <em>setter</em> method, <strong><em>model</em></strong>, on my_toyota, and set the instance variable <strong>@car_model </strong>to equal “Toyota”. Next, we called the setter function, <strong><em>name</em></strong>, on our instance, which returned “Toyota”.</p><h3>Attribute Accessor Macros</h3><p>Macros are an abstraction of setter and getter functions. They’re similar to methods. Using macros allows use to create both setters and gettersbut with only 1 line of code!</p><p>These are 3 basic macros that you’re likely to see:</p><pre><strong>attr_reader</strong> :name<strong><br>attr_writer</strong> :name<strong><br>attr_accessor</strong> :name</pre><ul><li><strong>attr_reader</strong> creates a getter function</li><li><strong>attr_writer</strong> creates a setter function</li><li><strong>attr_accessor</strong> creates both a setter and a getter function</li></ul><p>What follows each macro, in this case :name, is an attribute that the macro works on. <strong><em>attr_reader :name </em></strong>creates.</p><p>To reiterate, the following would function the same way:</p><pre># example A will output the same result as example B</pre><pre><em># example A</em><br>class Car<br>   attr_accessor :model<br>end</pre><pre>toyota = Car.new<br>toyota.model = &quot;Rav4&quot;</pre><pre>toyota.model<br># =&gt; &quot;Rav4&quot;</pre><pre># ------</pre><pre><em># example B</em><br>class Car<br>   def model=(model_name)<br>      @car_model = model_name<br>   end</pre><pre>   def model<br>      @car_model<br>   end<br>end</pre><pre>toyota = Car.new<br>toyota.model = &quot;Rav4&quot;</pre><pre>toyota.model<br># =&gt; &quot;Rav4&quot;</pre><p>As you can see in the example above, both situations output the same results. Using macros is usually preferred, because it uses less code and is easier to read.</p><h3>Object Initialization</h3><p>This allows us to create a new instance of a class, but to give it specific data upon its creation. The <strong>#initialize</strong> method is automatically called on a class when a new instance is created.</p><pre>class Car<br>   attr_reader :model<br>   attr_accessor :year</pre><pre>   def <strong>initialize</strong>(model, year)<br>      @model = model<br>      @year = year<br>   end</pre><pre>end</pre><pre>toyota = Car.new(&quot;Rav4&quot;, 2020)</pre><pre>toyota.year<em><br># =&gt; 2020</em></pre><pre>toyota.year = 2022<br>toyota.year<br><em># =&gt; 2022</em></pre><pre>toyota.model<br><em># =&gt; &quot;Rav4&quot;</em></pre><pre>toyota.model = &quot;4 Runner&quot;<br><em># =&gt; NoMethodError: undefined method `model=&#39; for #&lt;Car:0x00007fc920813710 @model=&quot;Rav4&quot;, @year=2022&gt;</em></pre><p>Let’s break down what happened above.</p><p>Our initialize method has 2 parameters: model and year. When creating a new instance of the Car class, you can pass in 2 arguments, and these will be set as instance variables (note the @ sign before each variable).</p><p>To touch on macros a bit more. There 2 macros, attr_reader, and attr_accessor. attr_reader only creates a setter function for model, so if you try to change the model attribute after its initialization, Ruby will throw a <em>NoMethodError</em>. If we used attr_writer, or attr_accessor on model, both cases would have created a setter function we could have used.</p><p>On the other hand, we’re able to change the value of the year attribute after its initialization. This is because we called attr_accessor :year, which creates both a setter and a getter function for it.</p><h3>Self</h3><p>If you’re coming from JavaScript, <strong><em>self</em></strong> is similar to <strong><em>this</em></strong>.</p><p>In Ruby, <strong><em>self</em></strong> refers to the instance that a method is being called on.</p><pre>class Car<br>   attr_accessor :model<br>   attr_accessor :year<br>   attr_accessor :make</pre><pre>   def <strong>initialize</strong>(make, model, year)<br>      @make = make<br>      @model = model<br>      @year = year<br>   end</pre><pre>   def year_model<br>      return &quot;Make: #{<strong>self</strong>.make}, Model: #{<strong>self</strong>.model}, year:    <br>      #{<strong>self</strong>.year}&quot;<br>   end</pre><pre>end</pre><pre>toyota1 = Car.new(&quot;Toyota&quot;, &quot;Rav4&quot;, 2020)<br>toyota1.year_model<br><em># =&gt; &quot;Make: Toyota, Model: Rav4, Year: 2020&quot;</em></pre><pre>toyota2 = Car.new(&quot;Honda&quot;, &quot;Accord&quot;, 2021)<br>toyota2.year_model<br><em># =&gt; &quot;Make: Honda, Model: Accord, Year: 2021&quot;</em></pre><p>In the example, <em>toyota1</em><strong><em> </em></strong>was instantiated with 3 variables: make, model and year. After the class was created, these variables became attributes of this new <em>toyota</em> instance, and now belong to it.</p><p><em>toyota2</em> was instantiated with different attributes than <em>toyota1</em>, so calling the <em>self</em> method on both of these instances will give a different result.</p><h3>Conclusion</h3><p>This article only touched on the very basics of Ruby classes. There are some more advanced topics, including class methods, class variables, and private methods. Self also goes deeper than I touched on here. I might elaborate on these more in a future article. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37927197e796" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Simple API Using Active Record and Sinatra]]></title>
            <link>https://medium.com/@personnamedmike/how-to-build-a-simple-api-using-active-record-and-sinatra-1bf461adb8a6?source=rss-949bd777c94e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bf461adb8a6</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[sinatra]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[starrdev]]></dc:creator>
            <pubDate>Thu, 10 Mar 2022 14:26:08 GMT</pubDate>
            <atom:updated>2022-03-10T14:26:08.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*pv09muXJu9AfW1K5AJTFqQ.png" /></figure><p>This article assumes a basic understanding of how Active Record and Sinatra work.</p><p>You can get some basic starter code by <a href="https://github.com/learn-co-curriculum/phase-3-sinatra-react-project">forking and cloning this repository</a> and running <strong><em>bundle install</em></strong><em>.</em></p><p><strong>Basic Active Record migrations setup:</strong></p><ul><li>Create directory <strong>app/models</strong>. Your database models and application controller file will live here</li><li>Create models. File names should be lowercase (for example, expense.rb). Class names should be singular and with the first letter capitalized. For example, <strong>class Expense</strong></li><li>Create new migration files with the following command (replace create_models with a name of your choosing, and make sure _models is plural): <strong><em>bundle exec rake db:create_migration NAME=create_models</em></strong></li><li>Edit your migration files. Syntax is here: <a href="https://guides.rubyonrails.org/v3.2/migrations.html">https://guides.rubyonrails.org/v3.2/migrations.html</a></li><li>table names should be lower case, and plural versions of their corresponding models. For example, model name = <strong>expense</strong>, and table name = <strong>expenses</strong></li><li>Run migrations with the following command: <strong><em>bundle exec rake db:migrate</em></strong></li><li>After migrations complete, check your <strong>schema.rb</strong> file</li><li>To undo a migration: <strong><em>bundle exec rake db:rollback</em></strong></li><li>To delete your database: <strong><em>bundle exec rake db:drop</em></strong></li><li>In db/migrate folder in <strong>seeds.rb</strong> file, fill out seed data. <a href="https://github.com/faker-ruby/faker"><strong>Ruby Faker Gem</strong></a><strong> </strong>might be useful. Using and run the following code to populate your database with dummy data. <strong><em>bundle exec rake db:seed</em></strong></li><li>Run <strong><em>bundle exec rake console</em></strong> to view and manipulate data from your database</li></ul><p><strong>Building an API with Sinatra:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*N3CpmaOhP1SzRKOr3jSVtQ.png" /></figure><p>Navigate to <strong>app/controllers/application_controllers.rb</strong></p><p>If you want your API to return json objects by default, enter this code at the top of the file below the class declaration: <strong><em>set :default_content_type, ‘application/json’</em></strong></p><p>Syntax for creating endpoints is the following:</p><pre>get “/endpoint” do</pre><pre> #code goes here</pre><pre>end</pre><p><strong><em>get</em></strong> can be replaced with any HTTP verb. For example:</p><pre>delete “/endpoint/:id” do</pre><pre>#code goes here</pre><pre>end</pre><p>You may have noticed the colon syntax in front of id in the example above. This indicates that it’s a dynamic route.</p><p><strong>Sinatra Dynamic Routes</strong></p><p>Dynamic routes allow for variables to be passed into a route. Take this endpoint for example: <a href="http://localhost:9292/expenses/:id"><strong>http://localhost:9292/expenses/:id</strong></a></p><p>:id is a dynamic variable which you, (the developer), can access and manipulate on the backend. What gets passed into :id gets passed into a hash called <strong>params</strong>. This with a special built in Sinatra method.</p><p>A client passing in the following endpoint: <strong>http://localhost:9292/expenses/5</strong> will create the following hash: params = { id =&gt; 5 }. From here, you can use <strong>id =&gt; 5</strong> to access data as needed</p><p><strong>How To Connect A React Frontend To A Sinatra Backend</strong></p><p>If you’re developing a full stack app using React and Sinatra, make 2 separate git repositories. 1 for the backend, and a separate for the frontend.</p><p>When your server is up and running on the backend, you can connect your React frontend by making fetch requests. With the example above, when your React app makes a GET request to <strong>http://localhost:9292/expenses/5, </strong>data from your backend will get sent to React, and you can manipulate it as necessary.</p><p>—</p><p><strong>In conclusion</strong>, creating a simple API with Active Record and Sinatra is quite simple. These Ruby Gems have abstracted away so much complexity, that it takes minimal code to get started.</p><p>During my time at <a href="https://flatironschool.com/">Flatiron School</a> as a software engineering student, I used the checklist in this article to help me get a basic understanding of how these technologies work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bf461adb8a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>