<?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 Anand Kumar K on Medium]]></title>
        <description><![CDATA[Stories by Anand Kumar K on Medium]]></description>
        <link>https://medium.com/@anandkumar211007?source=rss-99214433cc86------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xSkdtHZ9T5RI-cW3</url>
            <title>Stories by Anand Kumar K on Medium</title>
            <link>https://medium.com/@anandkumar211007?source=rss-99214433cc86------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:30:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anandkumar211007/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[Cookies in JavaScript: A Comprehensive Guide]]></title>
            <link>https://medium.com/@anandkumar211007/cookies-in-javascript-a-comprehensive-guide-7dbfa59ac3dc?source=rss-99214433cc86------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dbfa59ac3dc</guid>
            <dc:creator><![CDATA[Anand Kumar K]]></dc:creator>
            <pubDate>Fri, 31 May 2024 10:23:40 GMT</pubDate>
            <atom:updated>2024-05-31T10:23:40.526Z</atom:updated>
            <content:encoded><![CDATA[<p>Cookies are an essential part of web development, enabling websites to store small pieces of data on the client’s machine. This data persists across sessions and allows websites to remember user information, preferences, and other details. In JavaScript, handling cookies is a fundamental skill for building dynamic and interactive web applications. In this article, we’ll delve into the world of cookies, exploring how to create, read, update, and delete them using JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*574FkqxoilfX5L9r2Ducug.jpeg" /></figure><p>Cookies are small pieces of data stored in the user’s browser. They consist of a key-value pair and additional attributes such as expiration date, domain, and path. Websites use cookies for various purposes, including session management, user authentication, and tracking user behavior.</p><h3>Creating Cookies</h3><p>In JavaScript, you can create cookies using the document.cookie property. Here&#39;s how you can set a cookie:</p><pre>document.cookie = &quot;username=John Doe; expires=Thu, 31 Dec 2024 23:59:59 GMT; path=/&quot;;</pre><p>This code snippet sets a cookie named “username” with the value “John Doe”. It also specifies an expiration date and path for the cookie.</p><h3>Reading Cookies</h3><p>To read cookies in JavaScript, you can access the document.cookie property. Here&#39;s how you can retrieve the value of a cookie:</p><pre>const cookies = document.cookie.split(&#39;; &#39;);<br>const cookieMap = {};<br>cookies.forEach(cookie =&gt; {<br>    const [key, value] = cookie.split(&#39;=&#39;);<br>    cookieMap[key] = value;<br>});<br><br>const username = cookieMap[&#39;username&#39;];<br>console.log(username); // Output: User name</pre><p>This code snippet parses the document.cookie string and creates a map of cookies with their respective keys and values. You can then access the value of a specific cookie by its key.</p><h3>Updating Cookies</h3><p>To update a cookie, you can simply set it again with the desired value. Here’s how you can update the value of the “username” cookie:</p><pre>document.cookie = &quot;username=Jane Doe; expires=Thu, 31 Dec 2024 23:59:59 GMT; path=/&quot;;</pre><p>This code snippet updates the value of the “username” cookie to “Jane Doe”.</p><h3>Deleting Cookies</h3><p>To delete a cookie, you can set its expiration date to a past date. Here’s how you can delete the “username” cookie:</p><pre>document.cookie = &quot;username=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/&quot;;</pre><p>This code snippet sets the expiration date of the “username” cookie to January 1, 1970, effectively deleting it.</p><h3>Conclusion</h3><p>Cookies play a crucial role in web development, enabling websites to store user data and personalize user experiences. In JavaScript, managing cookies is straightforward, allowing developers to create, read, update, and delete cookies with ease. By mastering cookies in JavaScript, developers can enhance the functionality and interactivity of their web applications, providing users with a seamless browsing experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dbfa59ac3dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing Your React Skills: A Comprehensive Dive into React Hooks]]></title>
            <link>https://medium.com/@anandkumar211007/enhancing-your-react-skills-a-comprehensive-dive-into-react-hooks-d7309eedf9e1?source=rss-99214433cc86------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7309eedf9e1</guid>
            <dc:creator><![CDATA[Anand Kumar K]]></dc:creator>
            <pubDate>Fri, 24 May 2024 10:48:48 GMT</pubDate>
            <atom:updated>2024-05-24T10:48:48.989Z</atom:updated>
            <content:encoded><![CDATA[<p>React, a popular JavaScript library for building user interfaces, has significantly evolved since its inception. One of the most transformative additions to React is the introduction of Hooks in version 16.8. React Hooks allows developers to use state and other React features without writing a class. This article provides an overview of React Hooks, their benefits, and how to use some of the most common hooks in your React applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AV6zbaWPKR9HAhfIcQtF1A.jpeg" /></figure><h3>What are React Hooks?</h3><p>React Hooks are functions that let you “hook into” React state and lifecycle features from function components. They allow you to use state and other React features without writing a class component. Hooks were introduced to address several issues:</p><ol><li>Complexity in Class Components: Managing state and lifecycle methods in class components can be cumbersome and error-prone.</li><li>Logic Reuse: Hooks enable the reuse of stateful logic without changing the component hierarchy, making it easier to share logic between components or within the community.</li><li>Function Components: Many developers prefer function components over class components due to their simplicity and readability. Hooks empower function components with the full capabilities of React.</li></ol><h3>Commonly Used Hooks</h3><h4>1. useState</h4><p>The useState hook lets you add state to your functional components. It returns an array with two elements: the current state and a function to update it.</p><pre>import React, { useState } from &#39;react&#39;;<br><br>function Counter() {<br>  const [count, setCount] = useState(0);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Click me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>2. useEffect</h4><p>The useEffect hook lets you perform side effects in your components, such as data fetching, subscriptions, or manually changing the DOM. It runs after the first render and after every update.</p><pre>import React, { useState, useEffect } from &#39;react&#39;;<br><br>function Example() {<br>  const [count, setCount] = useState(0);<br><br>  useEffect(() =&gt; {<br>    document.title = `You clicked ${count} times`;<br>  }, [count]);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Click me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>3. useContext</h4><p>The useContext hook allows you to access the value of a context directly in your component without having to use a Consumer component.</p><pre>import React, { useContext } from &#39;react&#39;;<br><br>const ThemeContext = React.createContext(&#39;light&#39;);<br><br>function ThemeButton() {<br>  const theme = useContext(ThemeContext);<br><br>  return &lt;button className={theme}&gt;I am styled by theme context!&lt;/button&gt;;<br>}</pre><h4>4. useReducer</h4><p>The useReducer hook is usually preferable to useState when you have complex state logic that involves multiple sub-values or when the next state depends on the previous one. It’s similar to Redux but is built into React.</p><pre>import React, { useReducer } from &#39;react&#39;;<br><br>const initialState = { count: 0 };<br><br>function reducer(state, action) {<br>  switch (action.type) {<br>    case &#39;increment&#39;:<br>      return { count: state.count + 1 };<br>    case &#39;decrement&#39;:<br>      return { count: state.count - 1 };<br>    default:<br>      throw new Error();<br>  }<br>}<br><br>function Counter() {<br>  const [state, dispatch] = useReducer(reducer, initialState);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {state.count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;increment&#39; })}&gt;+&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;decrement&#39; })}&gt;-&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>5. useRef</h4><p>The useRef hook returns a mutable ref object whose .current property is initialized to the passed argument. This object will persist for the full lifetime of the component.</p><pre>import React, { useRef } from &#39;react&#39;;<br><br>function TextInputWithFocusButton() {<br>  const inputEl = useRef(null);<br><br>  const onButtonClick = () =&gt; {<br>    inputEl.current.focus();<br>  };<br><br>  return (<br>    &lt;&gt;<br>      &lt;input ref={inputEl} type=&quot;text&quot; /&gt;<br>      &lt;button onClick={onButtonClick}&gt;Focus the input&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h3>Benefits of Using Hooks</h3><ol><li>Simplified Components: Hooks simplify the logic of components, making them easier to read and maintain.</li><li>Reusability: Hooks allow you to reuse stateful logic without changing your component hierarchy.</li><li>Testability: Functional components with hooks are easier to test than class components.</li><li>Reduced Boilerplate: Hooks reduce the amount of code and boilerplate needed compared to class components.</li></ol><h3>Conclusion</h3><p>React Hooks represent a significant advancement in how React components can be written and managed. They provide a powerful and expressive way to use state and lifecycle features within functional components, leading to cleaner, more understandable, and more maintainable code. By mastering hooks like useState, useEffect, useContext, useReducer, and useRef, you can take full advantage of the capabilities of React and build more efficient and robust applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7309eedf9e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Props and State in React.js]]></title>
            <link>https://medium.com/@anandkumar211007/understanding-props-and-state-in-react-js-f0ab7d7e4e6e?source=rss-99214433cc86------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0ab7d7e4e6e</guid>
            <dc:creator><![CDATA[Anand Kumar K]]></dc:creator>
            <pubDate>Wed, 22 May 2024 10:16:12 GMT</pubDate>
            <atom:updated>2024-05-22T10:16:12.020Z</atom:updated>
            <content:encoded><![CDATA[<p>React.js, a popular JavaScript library for building user interfaces, operates on two fundamental concepts: props and state. Both are essential for managing data and controlling the behavior of React components. In this article, we’ll delve into what props and state are, how they differ, and how they are utilized within React applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SWmxJ4S6tRVQrrUMFqx35Q.jpeg" /></figure><h4>Props: Passing Data to Components</h4><p>Props, short for properties, are a way of passing data from parent to child components in React. They are immutable and are used to customize and configure child components. Props are passed down the component tree, making it easy to maintain a hierarchical structure of components with varying functionalities.</p><h4>Example:</h4><p><strong>Parent Component.</strong></p><pre>// ParentComponent.js<br>import React from &#39;react&#39;;<br>import ChildComponent1 from &#39;./ChildComponent1&#39;;<br>import ChildComponent2 from &#39;./ChildComponent2&#39;;<br><br>const ParentComponent = () =&gt; {<br>  const greeting = &quot;Hello, React!&quot;;<br>  <br>  return (<br>    &lt;div style={{ backgroundColor: &quot;lightblue&quot;, padding: &quot;20px&quot; }}&gt;<br>      &lt;h1&gt;Parent Component&lt;/h1&gt;<br>      &lt;ChildComponent1 greeting={greeting} /&gt;<br>      &lt;ChildComponent2 /&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default ParentComponent;</pre><p><strong>Child Component 1.</strong></p><pre>// ChildComponent1.js<br>import React from &#39;react&#39;;<br><br>const ChildComponent1 = (props) =&gt; {<br>  return (<br>    &lt;div style={{ backgroundColor: &quot;lightgreen&quot;, padding: &quot;10px&quot; }}&gt;<br>      &lt;h2&gt;Child Component 1&lt;/h2&gt;<br>      &lt;p&gt;{props.greeting}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default ChildComponent1;</pre><h4>State: Managing Component Data</h4><p>While props are used to pass data from parent to child components, state is used to manage component-specific data that may change over time. Unlike props, state is mutable and controlled by the component itself.</p><h4>Example:</h4><p><strong>Child Component 2.</strong></p><pre>// ChildComponent2.js<br>import React, { useState } from &#39;react&#39;;<br><br>const ChildComponent2 = () =&gt; {<br>  const [count, setCount] = useState(0);<br><br>  const incrementCount = () =&gt; {<br>    setCount(count + 1);<br>  }<br><br>  return (<br>    &lt;div style={{ backgroundColor: &quot;lightyellow&quot;, padding: &quot;10px&quot; }}&gt;<br>      &lt;h2&gt;Child Component 2&lt;/h2&gt;<br>      &lt;p style={{ color: &quot;blue&quot; }}&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={incrementCount}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default ChildComponent2;</pre><p>In this example, ChildComponent1 receives props from its parent component ParentComponent, while ChildComponent2 manages its own state using the useState hook. ChildComponent2 displays a count that can be incremented by clicking a button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gFdLQ-R0I0WyNdPO-pHeLw.png" /></figure><p><a href="https://cydppy.csb.app/">https://cydppy.csb.app/</a></p><h4>Conclusion</h4><p>Props and state are fundamental concepts in React.js that enable dynamic and interactive user interfaces. By understanding how to use props to pass data between components and how to manage component-specific data with state, you can build powerful and flexible React applications.</p><p>Understanding Props and State in React.js allows developers to create modular, reusable, and maintainable code, essential for building complex user interfaces.</p><p>By leveraging props and state effectively, React developers can create interactive and dynamic web applications that provide an exceptional user experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0ab7d7e4e6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Dynamic Animations to React Components Using Framer Motion]]></title>
            <link>https://medium.com/@anandkumar211007/adding-dynamic-animations-to-react-components-using-framer-motion-c0a7d12de8a1?source=rss-99214433cc86------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a7d12de8a1</guid>
            <dc:creator><![CDATA[Anand Kumar K]]></dc:creator>
            <pubDate>Fri, 17 May 2024 09:15:52 GMT</pubDate>
            <atom:updated>2024-05-17T09:15:52.869Z</atom:updated>
            <content:encoded><![CDATA[<p>Adding animations to a web application can significantly enhance the user experience by making interactions feel more dynamic and engaging. React, combined with libraries like Framer Motion, makes it easy to add animations to your components. In this article, we’ll explore how to create an animated component using React and Framer Motion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MTMl2FMlMAV9oX9rCLVyuw.jpeg" /></figure><h4>Why Use Framer Motion?</h4><p>Framer Motion is a popular animation library for React that offers an easy-to-use API for creating complex animations. It provides:</p><ul><li>Simple and declarative syntax.</li><li>Integration with React’s component model.</li><li>High-performance animations with minimal effort.</li></ul><h4>Setting Up the Project</h4><p>First, let’s set up a new React project and install Framer Motion.</p><ol><li><strong>Create a new React project:</strong></li></ol><pre>npx create-react-app animated-component<br>cd animated-component</pre><p><strong>2. Install Framer Motion:</strong></p><pre>npm install framer-motion</pre><h4>Creating an Animated Component</h4><p>We’ll create a simple animated box that changes size and color when clicked.</p><p><strong>Step 1: Setting Up the Component</strong></p><p>Create a new file named AnimatedBox.js inside the src directory.</p><pre>import React, { useState } from &#39;react&#39;;<br>import { motion } from &#39;framer-motion&#39;;<br><br>function AnimatedBox() {<br>  const [isToggled, setIsToggled] = useState(false);<br><br>  return (<br>    &lt;div style={{ display: &#39;flex&#39;, justifyContent: &#39;center&#39;, alignItems: &#39;center&#39;, height: &#39;100vh&#39; }}&gt;<br>      &lt;motion.div<br>        animate={{<br>          scale: isToggled ? 1.5 : 1,<br>          backgroundColor: isToggled ? &#39;#ff0055&#39; : &#39;#0055ff&#39;,<br>        }}<br>        transition={{ duration: 0.5 }}<br>        style={{ width: 100, height: 100 }}<br>        onClick={() =&gt; setIsToggled(!isToggled)}<br>      /&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default AnimatedBox;</pre><p><strong>In this example:</strong></p><ul><li>We use the useState hook to manage the toggled state of the box.</li><li>The motion.div component from Framer Motion is used to animate the box.</li><li>The animate prop defines the animation properties (scale and backgroundColor).</li><li>The transition prop specifies the duration of the animation.</li><li>An onClick event toggles the state, triggering the animation.</li></ul><p><strong>Step 2: Using the Animated Component</strong></p><p>Now, let’s use our AnimatedBox component in the main application file. Open src/App.js and modify it to include the AnimatedBox component.</p><pre>import React from &#39;react&#39;;<br>import &#39;./App.css&#39;;<br>import AnimatedBox from &#39;./AnimatedBox&#39;;<br><br>function App() {<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;header className=&quot;App-header&quot;&gt;<br>        &lt;AnimatedBox /&gt;<br>      &lt;/header&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Here, we import the AnimatedBox component and include it within the main App component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*1HPVnb3M3km86m4UCDGRTw.gif" /></figure><p><a href="https://qf5j38.csb.app/">https://qf5j38.csb.app/</a></p><h4>Conclusion</h4><p>By using Framer Motion with React, you can easily add animations to your web applications, making them more interactive and visually appealing. The AnimatedBox component example demonstrates how to create a simple animation that responds to user interactions. As you become more familiar with Framer Motion, you can explore more advanced features and create complex animations to enhance the user experience further.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a7d12de8a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>