<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Paulo "Heres"</title>
    <description>The latest articles on Forem by Paulo "Heres" (@heres).</description>
    <link>https://forem.com/heres</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1251748%2F4f405605-6d97-4427-ac4f-4aae5f1ce6c8.jpg</url>
      <title>Forem: Paulo "Heres"</title>
      <link>https://forem.com/heres</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/heres"/>
    <language>en</language>
    <item>
      <title>Authentication vs Authorization: The API Injection Mistake You Might Be Making</title>
      <dc:creator>Paulo "Heres"</dc:creator>
      <pubDate>Thu, 17 Apr 2025 12:10:27 +0000</pubDate>
      <link>https://forem.com/heres/authentication-vs-authorization-the-api-injection-mistake-you-might-be-making-3fdc</link>
      <guid>https://forem.com/heres/authentication-vs-authorization-the-api-injection-mistake-you-might-be-making-3fdc</guid>
      <description>&lt;p&gt;When building secure APIs, developers often put a lot of effort into &lt;strong&gt;authentication&lt;/strong&gt;—verifying the identity of a user. But what about &lt;strong&gt;authorization&lt;/strong&gt;—deciding what that user is allowed to do?&lt;/p&gt;

&lt;p&gt;Ignoring or misconfiguring authorization is one of the most common security oversights in backend development. Even with a strong authentication system (like JWTs), attackers can &lt;em&gt;inject&lt;/em&gt; API calls and access data or perform actions they shouldn't.&lt;/p&gt;

&lt;p&gt;Let’s break down the difference, then look at a real example of what can go wrong—and how to fix it.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ Authentication vs 🚫 Authorization
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;What it Does&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Authentication&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Confirms &lt;em&gt;who you are&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;Login with email and password&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Authorization&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Confirms &lt;em&gt;what you can do&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;Check if the user is allowed to edit a post&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt; answers: &lt;em&gt;“Is this user really John?”&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorization&lt;/strong&gt; answers: &lt;em&gt;“Is John allowed to do this?”&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔑 Common Setup: JWT Authentication
&lt;/h2&gt;

&lt;p&gt;A common practice is to use JWT (JSON Web Token) to authenticate users. When a user logs in, the backend generates a JWT that includes some payload—usually the user’s ID or role.&lt;/p&gt;

&lt;p&gt;Here’s an example payload:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"user_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"12345"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"iat"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1713308160&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"exp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1713344160&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This token is signed and sent to the frontend. The client includes it in API requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /api/orders/98765
Authorization: Bearer eyJhbGciOi...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the backend, you might decode the token, extract &lt;code&gt;user_id&lt;/code&gt;, and trust it blindly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;decodedToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;orderId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orderId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ❌ What’s Wrong Here?
&lt;/h2&gt;

&lt;p&gt;The backend checks that the user is authenticated—but not whether they &lt;em&gt;own&lt;/em&gt; the order.&lt;/p&gt;

&lt;p&gt;Any user with a valid token can try this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /api/orders/any-other-user-id
Authorization: Bearer eyJhbGciOi...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an &lt;strong&gt;authorization failure&lt;/strong&gt;. You're trusting the JWT, but you're not checking whether the user is &lt;em&gt;authorized&lt;/em&gt; to access that specific record.&lt;/p&gt;

&lt;p&gt;This opens the door to &lt;strong&gt;API injection attacks&lt;/strong&gt;—where attackers manipulate API endpoints and access or modify other users’ data.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛡️ How to Fix It
&lt;/h2&gt;

&lt;p&gt;You must verify &lt;strong&gt;both&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user is authenticated (&lt;code&gt;JWT is valid&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;The user is authorized (&lt;code&gt;owns this resource or has permission&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  ✅ Example with Authorization Check:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;decodedToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;orderId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orderId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unauthorized&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, even if a user tries to inject a different &lt;code&gt;order_id&lt;/code&gt;, they’ll be denied access unless the order belongs to them.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔐 Pro Tip: Don’t Trust the Client
&lt;/h2&gt;

&lt;p&gt;Even if the frontend is “locked down,” &lt;strong&gt;never rely on the client to enforce rules&lt;/strong&gt; like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hiding buttons for admin-only actions&lt;/li&gt;
&lt;li&gt;Sending only their own &lt;code&gt;user_id&lt;/code&gt; in the request&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The client can be modified, spoofed, or reverse-engineered. All critical access rules must be validated on the backend.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Authentication gets you in the door.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authorization decides what you’re allowed to do once inside.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you only implement authentication, you’re trusting every user with a key to the building. Without proper authorization, they might still wander into rooms they shouldn’t be in.&lt;/p&gt;

&lt;p&gt;Audit your routes. Build role-based or resource-based access checks. Assume nothing from the frontend.&lt;/p&gt;

&lt;p&gt;And always remember: a valid JWT does &lt;strong&gt;not&lt;/strong&gt; mean unlimited access.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How I Landed My First Job as a Jr Fullstack Developer</title>
      <dc:creator>Paulo "Heres"</dc:creator>
      <pubDate>Sun, 06 Apr 2025 18:30:09 +0000</pubDate>
      <link>https://forem.com/heres/how-i-landed-my-first-job-as-a-jr-fullstack-developer-2aki</link>
      <guid>https://forem.com/heres/how-i-landed-my-first-job-as-a-jr-fullstack-developer-2aki</guid>
      <description>&lt;p&gt;Getting your first developer job is tough. There’s no sugar-coating it. It feels like everyone wants "junior developers" with 3+ years of experience. But hey—I'm here to tell you it is possible, and I want to share how I landed my first role as a Junior Fullstack Developer. Maybe it'll help someone who's on the same path.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;TL;DR&lt;/strong&gt;
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I interned at Thomson Reuters, which gave me some industry exposure.

But what really helped was building Proof of Concepts (POCs) every weekend to sharpen my coding and debugging skills.

I regularly opened random GitHub projects just to understand them—and see if I could tweak or improve them.

I focused on going deep into a few core languages instead of spreading myself too thin.

Being a Program Assistant (PA) also played a huge role. Helping first-year students made me better at reading code, explaining it, and thinking critically.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;
  
  
  Internships Are Great—but Don’t Stop There
&lt;/h2&gt;

&lt;p&gt;My internship at Thomson Reuters was a great first step. I got a taste of real-world development, learned how teams collaborate, and became more comfortable with version control, agile workflows, and deadlines.&lt;/p&gt;

&lt;p&gt;But internships are short, and honestly, they can only teach you so much. What made the biggest difference for me was what I did outside of that experience.&lt;/p&gt;




&lt;h2&gt;
  
  
  Weekend POCs: Small Projects, Big Impact
&lt;/h2&gt;

&lt;p&gt;Every weekend, I made it a goal to build something small—a Proof of Concept (POC). It didn’t need to be polished or complete, but it had to solve a problem or test a new idea.&lt;/p&gt;

&lt;p&gt;Sometimes it was an API that scraped data. Other times it was a basic frontend app with a cool UI feature I saw online. These mini-projects pushed me to Google harder, debug better, and get more comfortable jumping between backend and frontend.&lt;/p&gt;

&lt;p&gt;I wasn’t just writing code—I was learning how to think like a developer.&lt;/p&gt;




&lt;h2&gt;
  
  
  GitHub: My Favorite Study Tool
&lt;/h2&gt;

&lt;p&gt;One of the best pieces of advice I can give: pick a random project on GitHub, open it, and try to figure out what’s going on.&lt;/p&gt;

&lt;p&gt;Look at the file structure, read the README, try running it locally, and then break it. Yep—break it on purpose. Change stuff and see what happens. This not only improved my understanding of how real-world projects are built, but it also helped me become less afraid of code that wasn’t mine.&lt;/p&gt;

&lt;p&gt;Reading and understanding other people’s code is a superpower.&lt;/p&gt;




&lt;h2&gt;
  
  
  Depth &amp;gt; Breadth
&lt;/h2&gt;

&lt;p&gt;I used to feel pressured to learn everything: Python, JavaScript, TypeScript, Go, Rust, etc. But at some point, I realized I was skimming the surface of everything and mastering none.&lt;/p&gt;

&lt;p&gt;So I switched gears. I chose a few languages (JavaScript/TypeScript for frontend, Node.js for backend), and went deep. I learned the ins and outs, wrote unit tests, explored frameworks, and even contributed to open source.&lt;/p&gt;

&lt;p&gt;It’s better to be solid in a few things than shallow in many.&lt;/p&gt;




&lt;h2&gt;
  
  
  Teaching Is Learning (Being a PA Helped a Lot)
&lt;/h2&gt;

&lt;p&gt;As a Program Assistant helping first-year students, I got better at breaking down problems and explaining concepts clearly. To teach something well, you have to understand it deeply. So I spent more time reading code, preparing examples, and anticipating questions.&lt;/p&gt;

&lt;p&gt;This unexpectedly boosted my own learning, especially when I had to debug someone else’s work or guide them through logic step-by-step.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;If you're trying to land your first dev job, my biggest advice is: don’t just study code—live in it. Build things. Break things. Read code that’s not yours. Teach someone if you can.&lt;/p&gt;

&lt;p&gt;And remember, even the best developers started where you are now—curious, confused, and coding one weekend at a time.&lt;/p&gt;

&lt;p&gt;Good luck, and happy coding! 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Scroll SVG Path with Framer Motion</title>
      <dc:creator>Paulo "Heres"</dc:creator>
      <pubDate>Sat, 15 Feb 2025 20:31:16 +0000</pubDate>
      <link>https://forem.com/heres/scroll-svg-path-with-framer-motion-54el</link>
      <guid>https://forem.com/heres/scroll-svg-path-with-framer-motion-54el</guid>
      <description>&lt;p&gt;Hello! Over the past few days, I’ve been diving into the world of SVG path animations that respond to user scroll input. &lt;/p&gt;

&lt;p&gt;While the concept is fascinating, I found the original documentation a bit challenging to follow. So, I decided to break it down and share my learnings in this post. If you’ve ever wanted to create a scroll-based SVG path animation, this guide is for you. Let’s get started!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What Are SVG Path Animations?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;SVG (Scalable Vector Graphics) path animations allow you to animate the drawing of a path, creating effects like lines being drawn or shapes being revealed. When combined with scroll-based interactions, these animations can add a dynamic and engaging touch to your website.&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll use Framer Motion, a powerful animation library for React, to create an SVG path animation that unfolds as the user scrolls.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Code Breakdown&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s walk through the code step by step to understand how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Setting Up the Environment&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;First, ensure you have Framer Motion installed in your React project. If not, you can install it using:&lt;br&gt;
First, ensure you have Framer Motion installed in your React project. If not, you can install it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;framer-motion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;2. Importing Required Modules&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We’ll need a few tools from Framer Motion to make this work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useScroll&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useTransform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;motion&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;framer-motion&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;    useScroll: Tracks the scroll progress of a target element.&lt;/li&gt;
&lt;li&gt;    useTransform: Maps the scroll progress to a value we can use for animation.&lt;/li&gt;
&lt;li&gt;    motion: Provides animated components like motion.svg and motion.path.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3. Creating the Component&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here’s the main component that handles the animation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Flower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;scrollYProgress&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useScroll&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0.1 end&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0.7 end&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pathLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useTransform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scrollYProgress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;w-full pt-10 md:pt-20&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;svg&lt;/span&gt;
        &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;w-full&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="nx"&gt;viewBox&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0 0 1000 1000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="nx"&gt;preserveAspectRatio&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;xMidYMid meet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="nx"&gt;xmlns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://www.w3.org/2000/svg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;
          &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;pathLength&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
          &lt;span class="nx"&gt;strokeWidth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="nx"&gt;stroke&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;fill&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;M1.25,240.24c4.39-38.39...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;//use your own svg path!&lt;/span&gt;
        &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/motion.svg&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    useRef: Creates a reference to the container element, which we’ll track for scroll progress.&lt;/li&gt;
&lt;li&gt;    useScroll: Tracks the scroll progress of the referenced element. The offset property defines when the animation starts and ends relative to the viewport.&lt;/li&gt;
&lt;li&gt;    useTransform: Maps the scroll progress (scrollYProgress) to a pathLength value between 0 and 1. This controls how much of the path is visible.&lt;/li&gt;
&lt;li&gt;    motion.path: The SVG path element that gets animated. The pathLength property is dynamically updated based on the scroll progress.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. Customizing the SVG Path&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The d attribute in the  element defines the shape of the path. Replace the placeholder d value with your own SVG path data. You can generate this using tools like SVG Path Editor or export it from design software like Figma or Illustrator.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;How It Works&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;    As the user scrolls, the scrollYProgress value changes from 0 to 1.&lt;/li&gt;
&lt;li&gt;    This value is mapped to the pathLength property of the  element.&lt;/li&gt;
&lt;li&gt;    The pathLength property controls how much of the path is visible, creating the effect of the path being drawn.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Tips for Customization&lt;/strong&gt;
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Adjust the Offset:** Change the offset values in useScroll to control when the animation starts and ends.

**Add Multiple Paths:** You can animate multiple paths by adding more &amp;lt;motion.path&amp;gt; elements and mapping their pathLength to different scroll ranges.

**Experiment with Styles:** Customize the stroke, strokeWidth, and fill properties to match your design.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Final Thoughts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Scroll-based SVG path animations are a great way to add interactivity and visual interest to your website. With Framer Motion, the process becomes straightforward and highly customizable. I hope this guide helps you get started with your own animations. If you have any questions or want to share your creations, feel free to reach out!&lt;/p&gt;

&lt;p&gt;Happy coding! 🎉&lt;/p&gt;

</description>
      <category>framermotion</category>
      <category>svg</category>
      <category>scrollanimation</category>
      <category>react</category>
    </item>
    <item>
      <title>High Order Function !== Closure</title>
      <dc:creator>Paulo "Heres"</dc:creator>
      <pubDate>Mon, 08 Jan 2024 19:23:01 +0000</pubDate>
      <link>https://forem.com/heres/high-order-function-closures-29d8</link>
      <guid>https://forem.com/heres/high-order-function-closures-29d8</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Every closure is a higher-order function, but not every higher-order function is a closure. To be a closure, the inner function has to have access to the parameter of the outer function.&lt;/p&gt;




&lt;p&gt;Closures and higher-order functions may appear similar, but they have a key differentiation between them (someone I know didn't pass a recent interview for a summer job because he couldn't explain it!). Enough talk, let's get straight to the point:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are Closures?!&lt;/strong&gt;&lt;br&gt;
Closures are inner functions that can access the parameters of outer functions. In the example below, the &lt;code&gt;innerFunction&lt;/code&gt; can access and use the &lt;code&gt;val&lt;/code&gt; parameter from the &lt;code&gt;outerFunction&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;innerFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;anotherValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;anotherValue&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What are Higher-Order Functions?&lt;/strong&gt;&lt;br&gt;
Similar to closures, higher-order functions are a structure of a function, but they do not necessarily have to be closures.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;innerFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;anotherValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;anotherValue&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope that this may help you! 😁&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>closure</category>
    </item>
  </channel>
</rss>
