<?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 Seun Gbenle on Medium]]></title>
        <description><![CDATA[Stories by Seun Gbenle on Medium]]></description>
        <link>https://medium.com/@gbenleseun2016?source=rss-467963ed2167------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8j41c9YkKCK4Ozw9tcWdSw.png</url>
            <title>Stories by Seun Gbenle on Medium</title>
            <link>https://medium.com/@gbenleseun2016?source=rss-467963ed2167------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 20:48:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gbenleseun2016/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[State Management Using Redux]]></title>
            <link>https://medium.com/@gbenleseun2016/state-management-using-redux-38697c5b5b27?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/38697c5b5b27</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Tue, 04 Jun 2024 08:49:07 GMT</pubDate>
            <atom:updated>2024-06-04T08:49:07.006Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B0-l0IMJelf9MO5l.png" /></figure><p>State management in web applications is crucial for maintaining the application’s data in a predictable and organized manner. Redux is a popular library for managing state in JavaScript applications, especially in React applications. It follows a predictable state container pattern, which makes it easier to understand and maintain the application’s state.</p><p>Here’s a basic overview of how Redux works for state management:</p><ol><li><strong>Store: </strong>Redux stores the entire state of your application in a single JavaScript object called the “store”. This store is the single source of truth for your application’s state. You create the Redux store using the createStore() function from the Redux library.</li><li><strong>Actions:</strong> Actions are plain JavaScript objects that represent “events” or “occurrences” in your application. These actions are dispatched to the Redux store to update the state. Actions must have a type property that indicates the type of action being performed. For example:</li></ol><pre>const incrementCounter = () =&gt; ({<br> type: &#39;INCREMENT_COUNTER&#39;<br> });</pre><p>3. <strong>Reducers:</strong> Reducers are pure functions responsible for specifying how the application’s state changes in response to actions. Each reducer takes the current state and an action as arguments, and returns the new state based on that action. Reducers are combined using the combineReducers() function from Redux. For example:</p><pre>const counterReducer = (state = 0, action) =&gt; {<br> switch (action.type) {<br> case &#39;INCREMENT_COUNTER&#39;:<br> return state + 1;<br> default:<br> return state;<br> }<br> };<br>const rootReducer = combineReducers({<br> counter: counterReducer<br> });</pre><p>4. <strong>Dispatch: </strong>Actions are dispatched to the Redux store using the `dispatch()` function. This triggers the execution of the reducers, which in turn update the state based on the dispatched action. For example:</p><pre>store.dispatch(incrementCounter());</pre><p>5. <strong>Selectors:</strong> Selectors are functions used to extract specific pieces of data from the Redux store. They provide an abstraction layer over the state structure, making it easier to access data from the store in components. For example:</p><pre>const selectCounter = state =&gt; state.counter;</pre><p>6. <strong>Connect:</strong> React components can connect to the Redux store using the `connect()` function provided by the `react-redux` library. This function connects a component to the Redux store, allowing it to access state and dispatch actions as props. For example:</p><pre>import { connect } from &#39;react-redux&#39;;<br><br>const Counter = ({ counter, incrementCounter }) =&gt; (<br>    &lt;div&gt;<br>        &lt;p&gt;Counter: {counter}&lt;/p&gt;<br>        &lt;button onClick={incrementCounter}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>);<br><br>const mapStateToProps = state =&gt; ({<br>    counter: selectCounter(state)<br>});<br><br>const mapDispatchToProps = {<br>    incrementCounter<br>};<br><br>export default connect(mapStateToProps, mapDispatchToProps)(Counter);</pre><p>By following these principles, Redux provides a robust and scalable solution for managing state in complex web applications. It promotes a unidirectional data flow and helps in keeping the application’s state and logic organized and predictable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38697c5b5b27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[State Management Using React Context]]></title>
            <link>https://medium.com/@gbenleseun2016/state-management-using-react-context-9742212667c7?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/9742212667c7</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[context]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Wed, 15 May 2024 07:55:18 GMT</pubDate>
            <atom:updated>2024-06-04T08:51:39.665Z</atom:updated>
            <content:encoded><![CDATA[<p>In React development, managing state and passing data between components can be tasking, especially in large applications nested component trees. While prop drilling and component composition have been traditional solutions, they often lead to messy and unmaintainable code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*o6ReBz-Vd7CjgAQg.png" /></figure><h4>What is Prop Drilling?</h4><p>Prop drilling occurs when data needs to be passed through multiple layers of nested components, even if many of these components don’t use the data themselves, just to reach a component deep in the hierarchy where the data is actually needed. React Context API, a powerful tool for managing global state and providing a clean solution to prop drilling.</p><h4><strong>React Context consists three main components:</strong></h4><ol><li><strong>Provider:</strong> This component allows you to define the data that you want to share and make it available to all child components.</li><li><strong>Consumer:</strong> This component allows child components to consume the data provided by the Provider.</li><li><strong>Context Object:</strong> This is where the data is stored and can be accessed by both the Provider and Consumer components.</li></ol><h4>Implementing React Context</h4><p>Let’s start by implementing a simple example to illustrate how React Context works:</p><pre>// ThemeContext.js<br>import React from &#39;react&#39;;<br><br>// Create a new context<br>const ThemeContext = React.createContext();<br><br>// Export Provider and Consumer<br>export const ThemeProvider = ThemeContext.Provider;<br>export const ThemeConsumer = ThemeContext.Consumer;<br><br>export default ThemeContext;</pre><p>In this example, we create a new context called ThemeContext using React.createContext(). We then export ThemeProvider and ThemeConsumer components, which will be used to provide and consume the theme data, respectively.</p><p>Now, let’s use this context in an application:</p><pre>// App.js<br>import React from &#39;react&#39;;<br>import { ThemeProvider } from &#39;./ThemeContext&#39;;<br>import Header from &#39;./Header&#39;;<br>import Content from &#39;./Content&#39;;<br><br>const App = () =&gt; {<br>  const theme = &#39;light&#39;;<br><br>  return (<br>    &lt;ThemeProvider value={theme}&gt;<br>      &lt;Header /&gt;<br>      &lt;Content /&gt;<br>    &lt;/ThemeProvider&gt;<br>  );<br>}<br><br>export default App;</pre><pre>// Header.js<br>import React from &#39;react&#39;;<br>import { ThemeConsumer } from &#39;./ThemeContext&#39;;<br><br>function Header() {<br>  return (<br>    &lt;ThemeConsumer&gt;<br>      {theme =&gt; &lt;header style={{ background: theme === &#39;light&#39; ? &#39;#f0f0f0&#39; : &#39;#333&#39; }}&gt;Header&lt;/header&gt;}<br>    &lt;/ThemeConsumer&gt;<br>  );<br>}<br><br>export default Header;</pre><pre>// Content.js<br>import React from &#39;react&#39;;<br>import { ThemeConsumer } from &#39;./ThemeContext&#39;;<br><br>function Content() {<br>  return (<br>    &lt;ThemeConsumer&gt;<br>      {theme =&gt; &lt;div style={{ color: theme === &#39;light&#39; ? &#39;#333&#39; : &#39;#f0f0f0&#39; }}&gt;Content&lt;/div&gt;}<br>    &lt;/ThemeConsumer&gt;<br>  );<br>}<br><br>export default Content;</pre><p>In this example, we provide the theme data using the ThemeProvider in the App component and consume it in the Header and Content components using the ThemeConsumer.</p><h4>Usage and Best Practices</h4><p>While the above example demonstrates the basic usage of React Context, there are several advanced techniques and best practices to consider:</p><ol><li><strong>Using Context with Hooks: </strong>You can use the useContext hook to consume context within functional components, which simplifies the syntax and reduces boilerplate code.</li><li><strong>Optimizing Performance:</strong> Context provides a way to pass data through the component tree without directly passing props, but be cautious about unnecessary re-renders. You can optimize performance by memoizing context values or using memoization libraries like memoize-one.</li><li><strong>Splitting Contexts:</strong> Instead of using a single global context for your entire application, consider splitting your context into smaller, more focused contexts to improve modularity and reusability.</li><li><strong>Testing Context Providers and Consumers:</strong> When testing components that use context, make sure to provide mock implementations of context values to isolate and test the components in isolation.</li></ol><p>By understanding its fundamentals and best practices, you can effectively use React Context to build scalable and maintainable React applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9742212667c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating A Video Call App Using WEBRTC]]></title>
            <link>https://medium.com/@gbenleseun2016/creating-a-video-call-app-using-webrtc-ab75052f71ac?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab75052f71ac</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[webrtc]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Wed, 08 May 2024 21:05:52 GMT</pubDate>
            <atom:updated>2024-05-08T21:05:52.687Z</atom:updated>
            <content:encoded><![CDATA[<p>I know firsthand how tricky it can be to navigate the vast ocean of coding information, especially when you’re trying to build something as complex as a video call application. I spent quite a bit of time searching for the best method to create one that not only works well but is also straightforward to implement. After exploring numerous options, I finally settled on a method using WebRTC. WebRTC is a free and open-source project that provides web browsers and mobile applications with real-time communication via simple APIs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ulTCnKz_e3SRDThv" /></figure><h4>1: Understanding the Basics of WebRTC</h4><p>WebRTC (Web Real-Time Communication) is an HTML5 specification that supports browser-to-browser applications for voice calling, video chat, and file sharing without the need for internal or external plugins. It handles the complexities of real-time media by providing methods to directly establish a connection between browsers.</p><h4>2: Setting Up Your Project</h4><p>First, set up a basic web development environment:</p><ul><li>HTML/CSS/JavaScript: Basic knowledge is required.</li><li>Node.js: Ensure Node.js is installed for server-side code.</li><li>Express: A minimal and flexible Node.js web application framework to handle server-side operations.</li></ul><p>Create a new directory for your project and set up a new Node.js application:</p><pre>mkdir video-call-app<br>cd video-call-app<br>npm init -y<br>npm i socket.io nodemon express simple-peer</pre><p><strong>Socket.io</strong>: This is used for signaling, allowing peers to exchange session information and establish peer-to-peer connections.</p><p><strong>Express</strong>: Express is a web application framework for Node.js. It can be used to create a server to serve static files, handle HTTP requests for signalling, and manage routes for different parts of the application.</p><p><strong>Nodemon: </strong>Nodemon is a utility for Node.js that helps in restarting the Node application when file changes in the directory are detected. This eliminates the need to manually stop and restart the Node server every time you make changes to your code.</p><h4>3: Creating a Basic Server</h4><h4>Initialize the Server and Middleware</h4><p>First, include necessary modules and set up the Express application with some essential middleware:</p><pre>// Import necessary modules<br>const express = require(&#39;express&#39;);     // Express framework for handling HTTP requests<br>const http = require(&#39;http&#39;);           // Built-in Node.js module for creating HTTP server<br>const socketIO = require(&#39;socket.io&#39;);  // Library for enabling real-time bidirectional communication between web clients and servers<br>const path = require(&#39;path&#39;);           // Built-in Node.js module for working with file paths<br><br>// Create an Express application<br>const app = express();<br><br>// Create an HTTP server using the Express application<br>const server = http.createServer(app);<br><br>// Create a Socket.IO instance attached to the HTTP server<br>const io = socketIO(server);<br><br>// Serve static files (e.g., HTML, CSS, JavaScript) from the &#39;public&#39; directory<br>app.use(express.static(path.join(__dirname, &#39;public&#39;)));</pre><h4>Handle WebSocket Connections to listen for signalling messages between clients.</h4><p>Log messages for when a client connects and disconnects from the server. For real-time communication, listen for custom events like ‘signal’ from clients. Broadcast these events and data to all other connected clients for seamless interaction.</p><pre>// Listen for incoming connections<br>io.on(&#39;connection&#39;, socket =&gt; {<br>    // Log when a user connects<br>    console.log(&#39;A user connected&#39;);<br>    <br>    // Listen for disconnection event<br>    socket.on(&#39;disconnect&#39;, () =&gt; {<br>        // Log when a user disconnects<br>        console.log(&#39;User disconnected&#39;);<br>    });<br><br>    // Listen for &#39;signal&#39; event from a client<br>    socket.on(&#39;signal&#39;, data =&gt; {<br>        // Broadcast the &#39;signal&#39; event and data to all connected clients except the sender<br>        socket.broadcast.emit(&#39;signal&#39;, data);<br>    });<br>});<br><br>/ Define the port number to listen on<br>const PORT = process.env.PORT || 3000;<br><br>// Start the server and listen on the specified port<br>server.listen(PORT, () =&gt; {<br>    // Log a message indicating that the server is running and listening on the specified port<br>    console.log(`Server is running on port ${PORT}`);<br>});<br></pre><h4>Start the Server</h4><p>You need to start your server so it can begin handling requests. You can do this by running the command nodemon server.js.</p><h4>4: Writing HTML Markup</h4><p>To create the foundation for our web application, we need to write the HTML markup. This markup defines the structure of our webpage and includes elements for displaying video streams and interacting with the WebSocket server.</p><p>Here’s an example of the HTML markup:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;<br>    &lt;title&gt;Simple WebRTC Video Call&lt;/title&gt;<br>    &lt;style&gt;<br>      .video-container {<br>        display: flex;<br>      }<br>      video {<br>        width: 50%;<br>        border: 2px solid black;<br>        margin: 20px;<br>      }<br>    &lt;/style&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>   &lt;h1&gt;Simple WebRTC Video Call&lt;/h1&gt;<br>    &lt;!-- Container for holding local and remote videos --&gt;<br>    &lt;div class=&quot;video-container&quot;&gt;<br>      &lt;!-- Video element for displaying the local video stream --&gt;<br>      &lt;video id=&quot;localVideo&quot; autoplay&gt;&lt;/video&gt;<br>      &lt;!-- Video element for displaying the remote video stream --&gt;<br>      &lt;video id=&quot;remoteVideo&quot; autoplay&gt;&lt;/video&gt;<br>    &lt;/div&gt;<br>    &lt;!-- Script tags for including required JavaScript libraries --&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/socket.io-client/dist/socket.io.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/simple-peer/simplepeer.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;!-- Script tag for including custom JavaScript file --&gt;<br>    &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>The necessary JavaScript libraries are included using &lt;script&gt; tags. These libraries are:</p><ul><li>socket.io.js: This library provides WebSocket functionality and enables real-time communication between clients and servers.</li><li>simplepeer.min.js: This library simplifies WebRTC implementation by providing a high-level API for peer-to-peer communication.</li></ul><h4>5: Implementing JavaScript Logic:</h4><p>In this step, we’ll implement the JavaScript logic to handle WebRTC connections and video streaming. This logic will be responsible for setting up the peer connection, capturing video streams from the user’s camera, and handling signaling between clients.</p><p>Here’s a brief overview of what needs to be done:</p><ol><li>Access the user’s media devices (camera and microphone) to capture video streams.</li><li>Initialize a Socket.IO connection to enable real-time communication with the server.</li><li>Set up a peer connection using the simple-peer library to establish a direct connection between clients.</li><li>Handle signaling between clients to exchange session descriptions (SDP) and ICE candidates.</li><li>Display the local video stream in the designated video element.</li><li>Listen for incoming video streams from other clients and display them in the corresponding video element.</li></ol><pre>// Establish a Socket.IO connection to the server<br>const socket = io();<br><br>// Request access to the user&#39;s media devices (e.g., camera)<br>navigator.mediaDevices.getUserMedia({ video: true, audio: false })<br>    .then(stream =&gt; {<br>        // Once access is granted, display the local video stream<br>        const localVideo = document.getElementById(&#39;localVideo&#39;);<br>        localVideo.srcObject = stream;<br><br>        // Initialize a new SimplePeer instance for peer-to-peer communication<br>        const peer = new SimplePeer({<br>            initiator: true, // Set as the initiator of the connection<br>            trickle: false, // Disable trickle ICE (Interactive Connectivity Establishment) for faster connection establishment<br>            stream: stream // Pass the local media stream to the peer<br>        });<br><br>        // Listen for the &#39;signal&#39; event emitted by the peer<br>        peer.on(&#39;signal&#39;, data =&gt; {<br>            console.log(&#39;Signal data:&#39;, data); // Log the signal data for debugging purposes<br>            // Send the signal data to the server using Socket.IO<br>            socket.emit(&#39;signal&#39;, JSON.stringify(data));<br>        });<br><br>        // Listen for the &#39;signal&#39; event from the server<br>        socket.on(&#39;signal&#39;, data =&gt; {<br>            console.log(&#39;Received signal:&#39;, data); // Log the received signal data for debugging purposes<br>            // Process the signal data received from the server and respond accordingly<br>            peer.signal(JSON.parse(data));<br>        });<br><br>        // Listen for the &#39;stream&#39; event emitted by the peer when a remote stream is received<br>        peer.on(&#39;stream&#39;, remoteStream =&gt; {<br>            console.log(&#39;Received remote stream:&#39;, remoteStream); // Log the received remote stream for debugging purposes<br>            // Display the remote video stream in the corresponding video element<br>            const remoteVideo = document.getElementById(&#39;remoteVideo&#39;);<br>            remoteVideo.srcObject = remoteStream;<br>        });<br>    })<br>    .catch(error =&gt; {<br>        console.error(&#39;Error accessing media devices:&#39;, error); // Log any errors encountered while accessing media devices<br>    });</pre><h4>6: Running the Application</h4><ul><li><strong>Open the Application in a Web Browser</strong>: Once the server is running, open a web browser and navigate to the URL where the application is hosted (e.g., http://localhost:3000 if running locally).</li><li><strong>Grant Access to Media Devices:</strong> When prompted, grant the application access to your media devices (e.g., camera and microphone). This step is necessary for capturing and streaming video.</li></ul><p>By following the steps outlined in this guide, you can build a basic video call applications that facilitates peer-to-peer connection. You can improve the interface by adding buttons to easily control the camera and audio settings during calls. You could also add a screen recording feature and a ‘End Call’ button which would make it easier for users to wrap up their conversations smoothly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab75052f71ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performance Optimization in React]]></title>
            <link>https://medium.com/@gbenleseun2016/performance-optimization-in-react-4f7f7c8aae6c?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f7f7c8aae6c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 22:07:17 GMT</pubDate>
            <atom:updated>2024-04-17T22:07:17.275Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-U19TJAKFWC6AW-1" /></figure><p>React is known for its speed and efficiency, but as applications grow, they can become slow and sluggish. Let’s explore practical tips for optimizing React applications to ensure they remain fast and responsive.</p><h4>1. Using Immutable Data Structures</h4><p>Immutable data structures are types of data (like arrays, objects, or custom types) that, once created, cannot be changed. If you need to modify them, you create a new structure with the desired changes rather than altering the original directly. This is different from mutable data structures, where changes are made directly to the existing object. Examples include using using Object.freeze(), spreading objects {...obj}, or using array methods like .map(), .filter(), and .reduce() which return new arrays instead of modifying the original.</p><h4>2. Memoization with React.memo</h4><p>React.memo is a higher-order component for memoizing components. It allows you to prevent re-rendering components unless specific props have changed. It’s particularly useful for components that receive complex objects as props. Here’s a basic example of how you can implement React.memo:</p><pre>import React from &#39;react&#39;;<br><br>const MyComponent = React.memo(function MyComponent(props) {<br>  // Component implementation<br>  console.log(&quot;Component re-rendered!&quot;);<br>  return &lt;div&gt;{props.children}&lt;/div&gt;;<br>});</pre><p>In this example, MyComponent will only re-render if the props change. If props.children remains the same between renders, the console log won&#39;t execute again, indicating no re-render.</p><h4>4. Lazy Loading Components</h4><p>React’s lazy function and the Suspense component enable you to split your application into smaller bundles and load them only when needed. This not only reduces the initial load time but also spreads the loading over time, making the application feel faster.</p><pre>const OtherComponent = React.lazy(() =&gt; import(&#39;./OtherComponent&#39;));<br><br>function MyComponent() {<br>  return (<br>    &lt;React.Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>      &lt;OtherComponent /&gt;<br>    &lt;/React.Suspense&gt;<br>  );<br>}</pre><h4>3. Efficient State Management</h4><p>State management is crucial, especially in large-scale applications. Over-fetching or under-fetching data, or frequent state updates, can lead to performance bottlenecks.</p><p>Redux or Context API: Use them for global state management. Redux is great for large-scale apps, while the Context API is sufficient for smaller apps or more straightforward state.</p><h4>4. Optimizing Dependencies</h4><p>Third-party libraries can significantly impact your app’s performance. It’s essential to keep an eye on what libraries you are adding and how they affect your overall bundle size.</p><p>What You Can Do:</p><ul><li>Webpack Bundle Analyzer: Use tools like this to visualize your app’s bundle size and identify heavy libraries or dependencies.</li><li>Tree Shaking: Ensure your module bundler supports tree shaking, which eliminates unused code.</li></ul><h4>Conclusion</h4><p>Optimizing a React app involves a mixture of techniques, from reducing bundle size with code splitting to improving runtime performance through efficient rendering and state management. Start by applying these strategies gradually and monitor their impact. As always, the specific needs of your application will dictate which optimizations are most effective.</p><p>Remember, performance optimization is an ongoing process. As your app scales, continue testing, monitoring, and tweaking to ensure it remains as efficient as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f7f7c8aae6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue-ing Into The Future-Differences Between Vue 2 and Vue 3]]></title>
            <link>https://medium.com/@gbenleseun2016/vue-ing-into-the-future-differences-between-vue-2-and-vue-3-26ef47c6a756?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/26ef47c6a756</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Thu, 15 Feb 2024 22:15:44 GMT</pubDate>
            <atom:updated>2024-02-15T22:15:44.419Z</atom:updated>
            <content:encoded><![CDATA[<h3>Vue-ing Into The Future-Differences Between Vue 2 andVue 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*N8D499iSYDaKZDm9psU37w.png" /><figcaption>vue.js</figcaption></figure><p>The Vue.js framework has made a name for itself in web development, known for its straightforward, effective approach to crafting user interfaces. It supports the creation of complex, scale projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*z5Nui3LEqGUSnERucjzViA.png" /></figure><h3>What’s Really Changed?</h3><p><strong>Composition API: </strong>Vue 3 introduces the Composition API. It’s different from Vue 2’s Options API and lets you organize code in a way that’s supposed to be better. If you liked keeping your component options like methods, data, computed properties, and so on, neatly organized, Vue 3’s approach might take some getting used to.</p><p><strong>Performance Improvements: </strong>Vue 3 is also faster. It comes down to a more efficient Virtual DOM and a reactivity system that uses Proxies. These changes make apps run smoother, which is good, but it’s not like Vue 2 was particularly sluggish.</p><p><strong>Enhanced TypeScript Support: </strong>TypeScript support is better in Vue 3. If you’re into TypeScript, you’ll find Vue 3 more accommodating. It has improved type inference and makes it easier to use TypeScript features within Vue components.</p><p><strong>Upgraded Vue Router and Vuex Compatibility: </strong>Vue Router and Vuex now work better with Vue 3, thanks to updates that enhance their performance and add new features.</p><p><strong>Bundle Size Reduction: </strong>Vue 3 reduces the size of app bundles through a more efficient template compiler and code compression, resulting in quicker load times and smoother app performance.</p><p><strong>Improved Error Management and Debugging: </strong>For error handling and debugging, Vue 3 improves upon its predecessors by offering clearer error messages and warnings, aiding developers in fixing issues more effectively.</p><h3>Compatibility and Learning</h3><p>Moving to Vue 3 from Vue 2 could be a hassle if you have a large project. Vue 3 isn’t entirely backward compatible, so some refactoring will be required. Plus, learning the new Composition API and other changes in Vue 3 might take some time.</p><p><strong>References</strong></p><ul><li><a href="https://v3-migration.vuejs.org/?source=post_page-----e93a4391c0fe--------------------------------">Vue 3 Migration Guide | Vue 3 Migration Guide</a></li><li><a href="https://dev.to/emperorbrains/vue-2-vs-vue-3-exploring-the-evolution-of-vuejs-49lf">Vue 2 vs. Vue 3: Exploring the Evolution of Vue.js</a></li></ul><p><a href="https://www.albiorixtech.com/blog/vue2-vs-vue3-with-top-differences/">https://www.albiorixtech.com/blog/vue2-vs-vue3-with-top-differences</a>/</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26ef47c6a756" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering the Art of Debugging: Techniques That Actually Work]]></title>
            <link>https://medium.com/@gbenleseun2016/mastering-the-art-of-debugging-techniques-that-actually-work-ef27ac1b7fa3?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef27ac1b7fa3</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Thu, 30 Nov 2023 14:27:13 GMT</pubDate>
            <atom:updated>2023-11-30T15:32:04.147Z</atom:updated>
            <content:encoded><![CDATA[<p>Every developer knows the drill: you write code, and then you spend twice as much time debugging it.Debugging is as much an art form as it is a precise science. Picture yourself as a detective in the digital realm, where you play the role of both the investigator and, occasionally, the inadvertent perpetrator. <br>To aid you in this complex journey of debugging, here are some effective methods:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GuhluZ-rphcpXLtF" /></figure><h3>Embrace and Understand The Bug</h3><p>First things first, let’s change our mindset. Bugs are not your enemy; they are your teachers. Every bug is an opportunity to learn something new about your code, your approach, and even your thinking process.</p><p>The biggest mistake we often make is to dive into fixing a bug without fully understanding it. Take the time to reproduce the bug consistently. Document what’s happening and under what conditions. Sometimes, the process of just laying out the problem in detail brings you halfway to the solution.</p><h3>Simplify And Isolate</h3><p>Break down your problem. If your code is a big and complex, start dissecting it. Comment out sections, use a debugger to check variable values at different stages. Isolating where the problem occurs can dramatically narrow down your search for the culprit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BiQqx2AaCWVmZxvL" /></figure><h3>Rubber Duck Debugging</h3><p>Talk through your code and its issues aloud, perhaps to something non-living, like a rubber duck. Voicing your thoughts can shed new light on the problem and frequently sparks those enlightening ‘aha’ moments.</p><h3>Check the Environment</h3><p>Sometimes the bug isn’t in your code but in the environment it’s running in. Different operating systems, browser versions, or even time zones can affect your code in unexpected ways. Always consider the ecosystem your code lives in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ngC3GYzXuwMCBYoS" /></figure><h3>Go Back in Time</h3><p>Version control systems like Git are not just for collaboration. They are a time machine. If a bug has suddenly appeared, use your version history to find out when it first occurred. This can significantly narrow down where to look.</p><h3>Ask for Help (But Do Your Homework First)</h3><p>There’s no shame in asking for help. But before you do, make sure you’ve done your due diligence. Understand your problem well enough to explain it clearly. This not only helps your colleagues help you better but often you’ll find the solution yourself in the process of formulating your question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gw-Wk3nG1OV9NPef" /><figcaption>checkout whats wrong with the image 🫢</figcaption></figure><h3>Take a Break</h3><p>Sometimes the best thing to do is step away. Take a walk, grab a coffee, or just stare out of a window. It’s amazing how often solutions come to us when we’re not actively grinding away at the problem.</p><h3>Keep Learning</h3><p>Every bug is a lesson. Once you’ve solved it, take a moment to reflect. What did you learn? How can this new knowledge prevent future bugs or help you solve them faster?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BNr2-21rm4Jl4CCV" /></figure><h3>Celebrate Your Victory</h3><p>Finally, celebrate your success. Debugging can be a grueling process, and every bug squashed deserves its moment of glory. Share your victory with your team, write about it, or just do a little victory dance in your chair.</p><h3>CONCLUSION</h3><p>Debugging is an essential skill in a programmer’s toolkit. It’s not just about fixing problems but about understanding them, learning from them, and growing as a developer. So next time you’re faced with a bug, remember these techniques, take a deep breath, and dive in. The solution is out there, and you have all the tools to find it. Happy debugging…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef27ac1b7fa3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Dynamic Checkbox List with React: Check and Uncheck with IDs]]></title>
            <link>https://medium.com/@gbenleseun2016/creating-a-dynamic-checkbox-list-with-react-check-and-uncheck-with-ids-ea37eb3fc182?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea37eb3fc182</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[checkbox]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Wed, 20 Sep 2023 17:09:57 GMT</pubDate>
            <atom:updated>2023-09-20T18:08:38.097Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*GoETF7w0mQaK1yt3cjO4Kg.png" /><figcaption>checkbox list</figcaption></figure><p>Creating a simple static checkbox list in React is straightforward. However, when it comes to dynamically rendering checkboxes and ensuring each one has a unique identifier, things can get tricky. The primary challenges we face are:</p><ol><li><strong>Dynamic Rendering</strong>: Generating checkbox items dynamically from a list of data.</li><li><strong>Managing State</strong>: Keeping track of the checked and unchecked items in the list.</li><li><strong>User Interaction</strong>: Handling user interactions to toggle the checkboxes.</li></ol><h4>Dynamic Rendering:</h4><p>To dynamically render checkbox items, we can use the map function to iterate through a data array and generate a checkbox for each item. Here&#39;s a simplified example:</p><pre> roles: [<br>    {<br>      roleId: &quot;1&quot;,<br>      name: &quot;Student&quot;,<br>    },<br>    {<br>      roleId: &quot;2&quot;,<br>      name: &quot;Teacher&quot;,<br>    },<br>    {<br>        roleId: &quot;3&quot;,<br>        name: &quot;Principal&quot;,<br>      },<br>  ],;<br><br>const checkboxList = roles.map((role, index) =&gt; (<br>  &lt;label key={role.roleId}&gt;<br>    &lt;input type=&quot;checkbox&quot; value={role.roleId} /&gt;<br>    {item}<br>  &lt;/label&gt;<br>));</pre><h4>Managing State:</h4><p>To keep track of the checked and unchecked items, we can utilize React state. We can maintain an array that stores the selected items’ values. When a checkbox is checked or unchecked, we update the state accordingly.</p><pre>   const [selectedIds, setSelectedIds] = useState([]);<br><br>   const handleCheckboxChange = (event) =&gt; {<br>   const checkedId = event.target.value;<br>   if(event.target.checked){<br>    setSelectedId([...selectedIds,checkedId])<br>   }else{<br>    setSelectedId(selectedIds.filter(id=&gt;id !== checkedId))<br>   }<br>   }</pre><h4>User Interaction:</h4><p>Finally, we need to handle user interactions to toggle the checkboxes. We can achieve this by adding an onChange event handler to each checkbox.</p><pre>  &lt;input<br>   type=&quot;checkbox&quot;<br>   value={item.roleId}<br>   checked={selectedIds.includes(item.roleId)}<br>   onChange={(event) =&gt; { handleCheckboxChange(event) }}<br>   /&gt;</pre><h4>Select All Checkboxes with One</h4><p>We use a “Select All” master checkbox to control the state of all checkboxes. This feature is useful for situations where users want to toggle the selection of multiple items with a single click.</p><pre> &lt;input                            <br>  type=&quot;checkbox&quot;<br>  onChange={(event) =&gt; {<br>  handleMultipleCheckboxChange(event)<br>  }}<br>  /&gt;<br><br>const handleMultipleCheckboxChange= (event) =&gt; {<br>//getting an array of all roleIds<br>const rolesArray = roles.map(r=&gt;r.roleId);<br>//on check of the master checkbox, return all roleIds and on uncheck, an empty array<br>setSelectedId(event.target.checked ? rolesArray : [])<br>}</pre><h4>Conclusion:</h4><p>In this article, we explored how to create an interactive checkbox list in React and addressed the challenges of dynamic rendering, managing state, and handling user interactions and Selecting all checkboxes with one. By following these steps, you can build a flexible and responsive checkbox list component in your React applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea37eb3fc182" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guide to sign In with Google On the Expo platform using expo-auth-session.]]></title>
            <link>https://medium.com/@gbenleseun2016/guide-to-sign-in-with-google-on-the-expo-platform-using-expo-auth-session-9d3688d2107a?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d3688d2107a</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Wed, 06 Sep 2023 17:43:32 GMT</pubDate>
            <atom:updated>2023-09-06T17:43:32.348Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s interconnected world, integrating social sign-in options in your mobile apps can significantly enhance the user experience. Google Sign-In is one of the most popular authentication methods, and if you’re developing your mobile app using Expo, implementing it is easier than you might think. In this step-by-step guide, we’ll walk you through the process of adding Google Sign-In to your Expo project.</p><figure><img alt="google sign in image" src="https://cdn-images-1.medium.com/max/577/0*sPV2Yl67X0ZlVnMf.png" /></figure><h3>Prerequisite</h3><p>Google Developer Console: You need to create a project in the <a href="https://console.developers.google.com/">Google Developer Console</a> and set up OAuth credentials to enable Google Sign-In. Make sure you have your OAuth client ID and web client ID ready. To get the package name and bundle ID use the command</p><pre>npx expo prebuild</pre><p>and add them to the app.json.</p><pre>  &quot;ios&quot;: {<br>      &quot;supportsTablet&quot;: true,<br>      &quot;bundleIdentifier&quot;: &quot;host.exp.exponent&quot;<br>    },<br>    &quot;android&quot;: {<br>      &quot;adaptiveIcon&quot;: {<br>        &quot;foregroundImage&quot;: &quot;./assets/adaptive-icon.png&quot;,<br>        &quot;backgroundColor&quot;: &quot;#ffffff&quot;<br>      },<br>      &quot;package&quot;: &quot;host.exp.exponent&quot;<br>    },<br>       &quot;scheme&quot;:&quot;dating-app&quot;,<br><br>//In order to be able to deep link back into your app, you will need to set a scheme in your project</pre><p>To get the SHA-1 certificate fingerprint,use the command</p><pre>expo credentials:manager</pre><h3>Step 1: Create a New Expo Project</h3><p>You can do this by opening your terminal and typing in the command:</p><pre>npx create-expo-app &lt;name of your app here&gt;</pre><p>you can open it on visual studio code by typing this command in the terminal:</p><pre>code .</pre><h3>Step 2: Install Required Packages</h3><p>Navigate to your project directory and install the necessary packages:</p><pre>cd &lt;name of project created&gt;<br>npx expo install expo-auth-session expo-crypto expo-web-browser <br>react-native-web react-dom @expo/webpack -config <br>@react-native-async-storage/async-storage</pre><p>“expo-auth-session”- command will manage the sign in with google, “expo-crypto” is a peer dependency and must be installed alongside expo-auth-session, “expo-web-browser” will enable you sign in to google without leaving the application. “react-native-web, react-dom, @expo/webpack -config” enables you use react native on web, “@react-native-async-storage/async-storage” enables you store data from google without losing them on reload.</p><h3>Step 3: Configure OAuth Client IDs</h3><p>Now, you need to configure your OAuth client IDs from Google in your Expo project. Create a file named .env in the root of your project and add your client IDs as environment variables:</p><pre>ANDROID_CLIENT_ID=your_android_client_id<br>IOS_CLIENT_ID=your_ios_client_id<br>WEB_CLIENT_ID=your_web_client_id</pre><p>Replace your_android_client_id, your_ios_client_id, and your_web_client_id with the client IDs you obtained from the Google Developer Console.</p><h3>Step 4: Implement Google Sign-In</h3><p>In your project, open the file where you want to implement Google Sign-In (e.g., App.js), and follow these steps:</p><h4>Import Dependencies</h4><p>Import the necessary dependencies at the top of your file:</p><pre>import * as WebBrowser from &quot;expo-web-browser&quot;;<br>import * as Google from &quot;expo-auth-session/providers/google&quot;;<br>import AsyncStorage from &quot;@react-native-async-storage/async-storage&quot;;<br>import { ANDROID_CLIENT_ID, IOS_CLIENT_ID, WEB_CLIENT_ID } from &quot;@env&quot;;</pre><h4>Write a function to allow WebBrowser handle redirecting</h4><pre>WebBrowser.maybeCompleteAuthSession();</pre><h4>Define the required variables for the hooks</h4><pre> <br>  const [userInfo, setUserInfo] = useState(null);<br><br>  //client IDs from .env<br>  const config = {<br>    androidClientId: ANDROID_CLIENT_ID,<br>    iosClientId: IOS_CLIENT_ID,<br>    webClientId: WEB_CLIENT_ID,<br>  };<br><br>  const [request, response, promptAsync] = Google.useAuthRequest(config);<br><br>//request - An instance of AuthRequest that can be used to prompt the user for authorization. This will be null until the auth request has finished loading.<br>//response - This is null until promptAsync has been invoked. Once fulfilled it will return information about the authorization.<br>//promptAsync - When invoked, a web browser will open up and prompt the user for authentication. Accepts an AuthRequestPromptOptions object with options about how the prompt will execute.</pre><h4>Initialise google sign-in on button click</h4><pre>&lt;Button title= &quot;sign in with google&quot; onPress={()=&gt;{promptAsync()}}/&gt;</pre><h4>Write a function to get user info from token</h4><pre>const getUserInfo = async (token) =&gt; {<br>    //absent token<br>    if (!token) return;<br>    //present token<br>    try {<br>      const response = await fetch(<br>        &quot;https://www.googleapis.com/userinfo/v2/me&quot;,<br>        {<br>          headers: { Authorization: `Bearer ${token}` },<br>        }<br>      );<br>      const user = await response.json();<br>      //store user information  in Asyncstorage<br>      await AsyncStorage.setItem(&quot;user&quot;, JSON.stringify(user));<br>      setUserInfo(user);<br>    } catch (error) {<br>      console.error(<br>        &quot;Failed to fetch user data:&quot;,<br>        response.status,<br>        response.statusText<br>      );<br>    }<br>  };</pre><h3>Create a Sign-In Function</h3><p>Create a function to handle the Google Sign-In process:</p><pre>const signInWithGoogle = async () =&gt; {<br>  try {<br>    // Attempt to retrieve user information from AsyncStorage<br>    const userJSON = await AsyncStorage.getItem(&quot;user&quot;);<br><br>    if (userJSON) {<br>      // If user information is found in AsyncStorage, parse it and set it in the state<br>      setUserInfo(JSON.parse(userJSON));<br>    } else if (response?.type === &quot;success&quot;) {<br>      // If no user information is found and the response type is &quot;success&quot; (assuming response is defined),<br>      // call getUserInfo with the access token from the response<br>      getUserInfo(response.authentication.accessToken);<br>    }<br>  } catch (error) {<br>    // Handle any errors that occur during AsyncStorage retrieval or other operations<br>    console.error(&quot;Error retrieving user data from AsyncStorage:&quot;, error);<br>  }<br>};<br><br>//add it to a useEffect with response as a dependency <br>useEffect(() =&gt; {<br>  signInWithGoogle();<br>}, [response]);<br><br>//log the userInfo to see user details<br>console.log(JSON.stringify(userInfo))</pre><h3>Step 5: Test Your App</h3><p>You’re now ready to test your Google Sign-In integration. Run your Expo project using:</p><pre>//default<br>expo start<br><br>// for web only <br>expo start --web --https</pre><p>Open your project on Web, an Android or iOS simulator, or on a physical device using the Expo Go app. When you press the “Sign In with Google” button, the Google Sign-In process should initiate, and upon successful sign-in, you will see the user information logged to the console.</p><p><strong>References</strong></p><p><a href="https://docs.expo.dev/">https://docs.expo.dev</a></p><p><a href="https://youtu.be/BDeKTPQzvR4?si=kt9uusD25z1_TMYm">https://youtu.be/BDeKTPQzvR4?si=kt9uusD25z1_TMYm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d3688d2107a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Unbreakable Spirit of Samuel(A Story by ChatGPT)]]></title>
            <link>https://medium.com/@gbenleseun2016/harmony-reclaimed-the-unbreakable-spirit-of-samuels-second-chance-symphony-a-story-by-chatgpt-78bfd54e085f?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/78bfd54e085f</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[storytelling]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[chatbots]]></category>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Fri, 01 Sep 2023 10:59:27 GMT</pubDate>
            <atom:updated>2023-09-01T12:03:16.457Z</atom:updated>
            <content:encoded><![CDATA[<p>So I told chatGPT to write the best story ever and make it inspirational. Here’s what I got:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XUTxx6XNLXsFY5OWowB96g.jpeg" /></figure><p>In the heart of a tranquil town, where the sun painted golden streaks across rolling hills, lived a man named Samuel. He wasn’t a superstar or a prodigy, but he possessed something extraordinary — a spirit that refused to bow to life’s hardships and a heart that beat to the rhythm of his dreams.</p><p>Samuel’s story began like many others. As a child, he fell in love with music, captivated by the idea that melodies could tell stories and heal hearts. At the tender age of eight, he picked up his father’s old violin and, with trembling fingers, played his first, slightly out-of-tune note. That off-key note, though, marked the start of his lifelong affair with music.</p><p>Yet, life had a way of weaving its own symphony. As Samuel grew, responsibilities and setbacks overshadowed his musical dreams. He tucked away his beloved violin, like a cherished memory put in an attic, waiting for the day when it could be rediscovered.</p><p>But dreams have a funny way of refusing to stay silent. They whisper, sometimes softly, sometimes urgently, but they never truly disappear. And so, in the quiet moments of his life, Samuel’s heart would sing, a haunting melody that urged him not to forget.</p><p>When Samuel reached the age of 30, he stood at a crossroads. His heart’s song had grown too powerful to ignore. The time had come to chase his dream with all the fire within him. So, he saved every dime, left behind his steady job, and embarked on a journey into the unknown, determined to become the musician he’d always longed to be.</p><p>The path was anything but easy. Doubters tried to sway him, finances threatened to crumble beneath him, and self-doubt occasionally crept in like a shadow. But Samuel clung to his dream as if it were a lifeline.</p><p>Years rolled on, and Samuel’s fingers danced on the strings with newfound expertise. His skill was undeniable, but his age was a relentless reminder that time waits for no one. Then, like a whisper in the wind, he heard about an international music competition — one that promised the chance to perform with a world-renowned orchestra.</p><p>Every note Samuel played in that competition told the story of his life. It carried the weight of his struggles and the depth of his dreams. The audience sat spellbound, moved by the raw emotion in his music.</p><p>When he finished, the auditorium burst into applause. The judges, with tears in their eyes, announced Samuel as the winner. He had proven that dreams don’t have an age limit.</p><p>In that moment, Samuel realized that dreams, once awakened, know no boundaries. His victory was not just about music; it was about the power of second chances.</p><p>His story traveled far and wide, a melody that resonated with anyone who ever thought it was too late to follow their heart. Samuel’s journey taught us that the most beautiful melodies often emerge from life’s struggles, and it’s never too late to create your own symphony of success.</p><p>Samuel’s life was like a crescendo — a gradual rise to greatness. May his story inspire you to rekindle your own passions, no matter where you are in life’s journey, and to compose the masterpiece of your own life, one note at a time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78bfd54e085f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effortlessly Selecting One Item at a Time from An Array/List with onClick Event Using React.]]></title>
            <link>https://medium.com/@gbenleseun2016/effortlessly-selecting-one-item-at-a-time-from-an-array-list-with-onclick-event-using-react-270ff90f26c0?source=rss-467963ed2167------2</link>
            <guid isPermaLink="false">https://medium.com/p/270ff90f26c0</guid>
            <dc:creator><![CDATA[Seun Gbenle]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 13:50:24 GMT</pubDate>
            <atom:updated>2023-08-02T13:50:24.590Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Introduction</em></p><p>Greetings, fellow React enthusiasts! Today, we embark on a fascinating journey into the world of interactive user interfaces. Our mission is to learn how to harness the onClick event in React and use its power to elegantly select items from an array. Whether you’re a seasoned developer or just starting with React, this guide will demystify the process and empower you to create engaging user experiences.</p><p><em>Step-by-Step Implementation</em></p><p>Now, let’s roll up our sleeves and delve into the code. We’ll guide you through each step, explaining the logic behind the implementation.</p><p><em>Step 1: Setting Up the Grocery List Component</em></p><p>To begin, let’s create a functional component named <strong>GroceryList</strong>. Inside this component, we&#39;ll set up two state variables: <strong>changeColor</strong> and <strong>indexRow</strong>, both of which will be managed by React&#39;s <strong>useState</strong> hook. These states will play a crucial role in determining the selected item and applying visual cues for the users.</p><pre>import React, { useState } from &quot;react&quot;;<br><br>function GroceryList() {<br>  const [changeColor, setChangeColor] = useState(false);<br>  const [indexRow, setIndexRow] = useState(false);<br><br>  // The array of grocery items will be added here later.<br><br>  // Let&#39;s continue to the next step!<br>}</pre><p><em>Step 2: Rendering the Grocery Items with onClick Event</em></p><p>Now that the foundation is laid, let’s proceed to render the grocery items as captivating cards on the screen. For each item card, we’ll attach the <strong>onClick</strong> event, which will enable users to interact with the list and select their desired item.</p><pre>return (<br>  &lt;div className=&quot;d-flex justify-content-center my-5&quot;&gt;<br>    &lt;div&gt;<br>      &lt;h2&gt;Groceries&lt;/h2&gt;<br>      &lt;div className=&quot;d-flex mt-3&quot;&gt;<br>        {/* The magic of JavaScript mapping - creating cards for each item! */}<br>        {/* onClick event to be implemented in the next step */}<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>);</pre><p><em>Step 3: Implementing the onClick Event Logic</em></p><p>Now comes the enchanting part! We’ll define a function called <strong>handleItemClick</strong> that will be triggered when a user clicks on a grocery item card. This function will update the state variables <strong>indexRow</strong> and <strong>changeColor</strong>, ensuring that the selected item is highlighted with a green background.</p><pre>function GroceryList() {<br>  // Previous code...<br><br>  const handleItemClick = (selectedIndex) =&gt; {<br>    // The magic of onClick - updating the selected item and visual cues!<br>    setIndexRow(selectedIndex);<br>    setChangeColor(true);<br>  };<br><br>  // Let&#39;s continue to the final step!<br>}</pre><p><em>Step 4: Finalizing the Grocery List Component</em></p><p>We’ve come to the final step! All that’s left is to integrate the <strong>handleItemClick</strong> function into the JSX code, ensuring that each grocery item card has its <strong>onClick</strong> event set to invoke the magical function.</p><pre>return (<br>  &lt;div className=&quot;d-flex justify-content-center my-5&quot;&gt;<br>    &lt;div&gt;<br>      &lt;h2&gt;Groceries&lt;/h2&gt;<br>      &lt;div className=&quot;d-flex mt-3&quot;&gt;<br>        {groceries.map((item, idx) =&gt; (<br>          &lt;div<br>            key={idx}<br>            className={`card rounded ${<br>              indexRow === idx &amp;&amp; changeColor ? &quot;bg-success&quot; : &quot;bg-light&quot;<br>            } p-4 mx-3`}<br>            onClick={() =&gt; handleItemClick(idx)}<br>          &gt;<br>            &lt;div&gt;{item.items}&lt;/div&gt;<br>          &lt;/div&gt;<br>        ))}<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>);</pre><p><em>Conclusion</em></p><p>And there you have it! We’ve completed the step-by-step guide to effortlessly selecting one item at a time from an array/list with the <strong>onClick</strong> event using React.Throughout this step-by-step guide, we’ve witnessed the wonders of React’s <strong>useState</strong> hook and how it seamlessly manages the state variables <strong>changeColor</strong> and <strong>indexRow.</strong> These magical ingredients enabled us to apply visual cues, indicating the selected item with a mesmerizing green background.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=270ff90f26c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>