<?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>DEV Community: Amereen</title>
    <description>The latest articles on DEV Community by Amereen (@amereen).</description>
    <link>https://dev.to/amereen</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%2F942265%2F7f51994f-243d-4c7f-81de-9bbe7f2b72bd.png</url>
      <title>DEV Community: Amereen</title>
      <link>https://dev.to/amereen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amereen"/>
    <language>en</language>
    <item>
      <title>Exploring Redux as a Global State Management Solution: An In-Depth Guide</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Wed, 27 Mar 2024 21:36:17 +0000</pubDate>
      <link>https://dev.to/amereen/exploring-redux-as-a-global-state-management-solution-an-in-depth-guide-ng4</link>
      <guid>https://dev.to/amereen/exploring-redux-as-a-global-state-management-solution-an-in-depth-guide-ng4</guid>
      <description>&lt;p&gt;Introduction:&lt;br&gt;
Redux has emerged as a prominent tool for managing global state in React applications, valued for its reliability and scalability. In this blog post, we'll dive into the core principles of Redux as a global state management solution, uncovering its key concepts, advantages, and practical tips for successful implementation in React projects.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Understanding Global State Management:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Global state management involves handling application data that needs to be shared across multiple components within an application.&lt;/li&gt;
&lt;li&gt;Traditional React state management relies on passing props between components, which can become unwieldy as the application grows in complexity.&lt;/li&gt;
&lt;li&gt;Redux offers an alternative approach by centralizing state management in a single store, simplifying data access and updates across the application.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Key Concepts of Redux:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store: The Redux store acts as a centralized repository for application state, providing a single source of truth accessible to all components.&lt;/li&gt;
&lt;li&gt;Actions: Actions are payloads of information that trigger state changes in the Redux store. They are plain JavaScript objects containing a type property that describes the action.&lt;/li&gt;
&lt;li&gt;Reducers: Reducers specify how the application's state changes in response to actions. They are pure functions that take the current state and an action as input and return the new state.&lt;/li&gt;
&lt;li&gt;Dispatch: Dispatch is a function provided by the Redux store, used to send actions to the store for processing and state updates.&lt;/li&gt;
&lt;li&gt;Selectors: Selectors are functions that extract specific slices of state from the Redux store, enabling components to access relevant data in a structured manner.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Benefits of Redux:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Predictability: Redux promotes predictable state management by enforcing strict principles, facilitating easier debugging and maintenance.&lt;/li&gt;
&lt;li&gt;Scalability: Redux scales effectively with large applications, thanks to its centralized state management approach and structured data flow.&lt;/li&gt;
&lt;li&gt;Debugging Tools: Redux offers robust debugging tools such as Redux DevTools, which allow developers to inspect state changes and track action history for easier debugging.&lt;/li&gt;
&lt;li&gt;Middleware: Redux middleware extends its capabilities, enabling features like logging, asynchronous actions, and more, enhancing its flexibility and utility.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Best Practices for Redux Implementation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single Source of Truth: Centralize application state in the Redux store to maintain consistency and simplify data access.&lt;/li&gt;
&lt;li&gt;Pure Reducers: Ensure reducers remain pure functions without side effects, guaranteeing predictable state updates based solely on input.&lt;/li&gt;
&lt;li&gt;Normalized State Shape: Organize state in a normalized structure to improve data management and avoid redundancy.&lt;/li&gt;
&lt;li&gt;Selector Usage: Utilize selectors to encapsulate state access logic, promoting code reusability and decoupling components from the state structure.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Integrating Redux with React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React-Redux Library: The react-redux library facilitates seamless integration of Redux with React applications, providing bindings between Redux and React components.&lt;/li&gt;
&lt;li&gt;Connect Function: The connect function from react-redux connects React components to the Redux store, enabling access to state and dispatch functions.&lt;/li&gt;
&lt;li&gt;Provider Component: The Provider component from react-redux wraps the root component of the application, making the Redux store available to all components.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Conclusion:&lt;br&gt;
Redux serves as a powerful global state management solution for React applications, offering reliability, scalability, and centralized state management. By grasping its core concepts and adhering to best practices, developers can harness Redux effectively to manage complex application state with ease. With Redux's robust architecture and smooth integration with React, developers can build scalable and maintainable applications that deliver an exceptional user experience.&lt;/p&gt;

</description>
      <category>redux</category>
      <category>codenewbie</category>
      <category>ruby</category>
      <category>programming</category>
    </item>
    <item>
      <title>Exploring Redux as a Global State Management Solution: An In-Depth Guide</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Wed, 27 Mar 2024 21:36:07 +0000</pubDate>
      <link>https://dev.to/amereen/exploring-redux-as-a-global-state-management-solution-an-in-depth-guide-fgc</link>
      <guid>https://dev.to/amereen/exploring-redux-as-a-global-state-management-solution-an-in-depth-guide-fgc</guid>
      <description>&lt;p&gt;Introduction:&lt;br&gt;
Redux has emerged as a prominent tool for managing global state in React applications, valued for its reliability and scalability. In this blog post, we'll dive into the core principles of Redux as a global state management solution, uncovering its key concepts, advantages, and practical tips for successful implementation in React projects.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Understanding Global State Management:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Global state management involves handling application data that needs to be shared across multiple components within an application.&lt;/li&gt;
&lt;li&gt;Traditional React state management relies on passing props between components, which can become unwieldy as the application grows in complexity.&lt;/li&gt;
&lt;li&gt;Redux offers an alternative approach by centralizing state management in a single store, simplifying data access and updates across the application.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Key Concepts of Redux:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store: The Redux store acts as a centralized repository for application state, providing a single source of truth accessible to all components.&lt;/li&gt;
&lt;li&gt;Actions: Actions are payloads of information that trigger state changes in the Redux store. They are plain JavaScript objects containing a type property that describes the action.&lt;/li&gt;
&lt;li&gt;Reducers: Reducers specify how the application's state changes in response to actions. They are pure functions that take the current state and an action as input and return the new state.&lt;/li&gt;
&lt;li&gt;Dispatch: Dispatch is a function provided by the Redux store, used to send actions to the store for processing and state updates.&lt;/li&gt;
&lt;li&gt;Selectors: Selectors are functions that extract specific slices of state from the Redux store, enabling components to access relevant data in a structured manner.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Benefits of Redux:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Predictability: Redux promotes predictable state management by enforcing strict principles, facilitating easier debugging and maintenance.&lt;/li&gt;
&lt;li&gt;Scalability: Redux scales effectively with large applications, thanks to its centralized state management approach and structured data flow.&lt;/li&gt;
&lt;li&gt;Debugging Tools: Redux offers robust debugging tools such as Redux DevTools, which allow developers to inspect state changes and track action history for easier debugging.&lt;/li&gt;
&lt;li&gt;Middleware: Redux middleware extends its capabilities, enabling features like logging, asynchronous actions, and more, enhancing its flexibility and utility.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Best Practices for Redux Implementation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single Source of Truth: Centralize application state in the Redux store to maintain consistency and simplify data access.&lt;/li&gt;
&lt;li&gt;Pure Reducers: Ensure reducers remain pure functions without side effects, guaranteeing predictable state updates based solely on input.&lt;/li&gt;
&lt;li&gt;Normalized State Shape: Organize state in a normalized structure to improve data management and avoid redundancy.&lt;/li&gt;
&lt;li&gt;Selector Usage: Utilize selectors to encapsulate state access logic, promoting code reusability and decoupling components from the state structure.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Integrating Redux with React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React-Redux Library: The react-redux library facilitates seamless integration of Redux with React applications, providing bindings between Redux and React components.&lt;/li&gt;
&lt;li&gt;Connect Function: The connect function from react-redux connects React components to the Redux store, enabling access to state and dispatch functions.&lt;/li&gt;
&lt;li&gt;Provider Component: The Provider component from react-redux wraps the root component of the application, making the Redux store available to all components.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Conclusion:&lt;br&gt;
Redux serves as a powerful global state management solution for React applications, offering reliability, scalability, and centralized state management. By grasping its core concepts and adhering to best practices, developers can harness Redux effectively to manage complex application state with ease. With Redux's robust architecture and smooth integration with React, developers can build scalable and maintainable applications that deliver an exceptional user experience.&lt;/p&gt;

</description>
      <category>redux</category>
      <category>codenewbie</category>
      <category>ruby</category>
      <category>programming</category>
    </item>
    <item>
      <title>Title: Mastering CRUD Operations in React with Redux Toolkit Query</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Wed, 27 Mar 2024 21:16:10 +0000</pubDate>
      <link>https://dev.to/amereen/title-mastering-crud-operations-in-react-with-redux-toolkit-query-acd</link>
      <guid>https://dev.to/amereen/title-mastering-crud-operations-in-react-with-redux-toolkit-query-acd</guid>
      <description>&lt;p&gt;Introduction:&lt;br&gt;
In modern web development, managing data fetching and mutation efficiently is essential for building responsive and dynamic applications. Redux Toolkit Query offers a powerful solution for simplifying data handling in Redux applications. In this blog post, we'll explore how Redux Toolkit Query revolutionizes data fetching and mutation, streamlining state management and enhancing developer productivity.&lt;/p&gt;

&lt;p&gt;Understanding Redux Toolkit Query:&lt;/p&gt;

&lt;p&gt;Redux Toolkit Query is a data fetching and caching library built on top of Redux Toolkit, designed to simplify API interactions in Redux applications.&lt;br&gt;
It provides a declarative API for defining API endpoints, fetching data, caching responses, and handling mutations, eliminating the need for writing boilerplate Redux logic.&lt;br&gt;
Fetching Data:&lt;/p&gt;

&lt;p&gt;With Redux Toolkit Query, fetching data from APIs becomes intuitive and straightforward. Developers can define API endpoints using the createApi function, specifying the base URL and expected endpoints.&lt;br&gt;
Autogenerated hooks such as useQuery enable components to fetch data effortlessly, abstracting away the complexities of Redux store subscription and data fetching logic.&lt;br&gt;
Caching Responses:&lt;/p&gt;

&lt;p&gt;Redux Toolkit Query automatically caches API responses, optimizing performance by avoiding unnecessary network requests.&lt;br&gt;
Cached data is automatically invalidated based on configurable criteria, ensuring that users always receive the latest data without compromising performance.&lt;br&gt;
Handling Mutations:&lt;/p&gt;

&lt;p&gt;Redux Toolkit Query simplifies mutation handling by providing autogenerated mutation hooks like useMutation.&lt;br&gt;
Developers can define mutation endpoints using the mutation property in the createApi configuration, specifying the HTTP method, URL, and request body.&lt;br&gt;
Autogenerated mutation hooks encapsulate the logic for sending mutation requests, handling loading states, and updating cached data, reducing boilerplate code and enhancing code readability.&lt;br&gt;
Optimistic Updates:&lt;/p&gt;

&lt;p&gt;Redux Toolkit Query supports optimistic updates, allowing UIs to update optimistically before the mutation request is completed.&lt;br&gt;
This provides a seamless user experience by instantly reflecting changes in the UI, even before receiving confirmation from the server.&lt;br&gt;
Error Handling and Retry Logic:&lt;/p&gt;

&lt;p&gt;Redux Toolkit Query simplifies error handling by providing built-in mechanisms for retrying failed requests and handling network errors.&lt;br&gt;
Developers can configure retry logic and customize error handling strategies, ensuring robustness and resilience in the face of network issues.&lt;br&gt;
Integrating with Redux Toolkit:&lt;/p&gt;

&lt;p&gt;Redux Toolkit Query seamlessly integrates with Redux Toolkit, leveraging Redux's powerful features like middleware, reducers, and selectors.&lt;br&gt;
Developers can combine Redux Toolkit Query with other Redux Toolkit utilities to build scalable and maintainable Redux applications.&lt;br&gt;
Conclusion:&lt;br&gt;
Redux Toolkit Query revolutionizes data fetching and mutation in Redux applications, offering a simple and declarative API for managing API interactions. By abstracting away complex Redux logic, Redux Toolkit Query streamlines state management, enhances developer productivity, and improves the overall user experience. With its support for caching, mutation handling, optimistic updates, and error handling, Redux Toolkit Query empowers developers to build robust and performant web applications with ease.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>redux</category>
      <category>ruby</category>
      <category>crud</category>
    </item>
    <item>
      <title>Implementing JWT Authentication in Ruby on Rails</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Mon, 18 Dec 2023 20:47:44 +0000</pubDate>
      <link>https://dev.to/amereen/implementing-jwt-authentication-in-ruby-on-rails-5bbl</link>
      <guid>https://dev.to/amereen/implementing-jwt-authentication-in-ruby-on-rails-5bbl</guid>
      <description>&lt;p&gt;User authentication is a pivotal component of web development, ensuring that only authorized individuals can access your application's resources. In this guide, we'll delve into the implementation of JWT (JSON Web Tokens) authentication in a Ruby on Rails project. This method offers stateless and secure authentication and is widely embraced in modern web development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JWT Authentication Unveiled&lt;/strong&gt;&lt;br&gt;
JSON Web Tokens (JWTs) are the building blocks of secure authentication. They are self-contained tokens that convey user identity and are an excellent choice for authenticating users in your Ruby on Rails application. A JWT consists of three parts: a header, a payload, and a signature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header&lt;/strong&gt;: This part contains metadata, including the token's type and the signing algorithm used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Payload&lt;/strong&gt;: Here, you'll find claims or statements about the user's identity and additional data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Signature&lt;/strong&gt;: This part ensures the token's integrity by verifying that it hasn't been tampered with during transmission.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why JWT Authentication in Ruby on Rails?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JWT authentication provides several advantages when applied in a Ruby on Rails project:&lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Stateless Authentication:&lt;/strong&gt; By design, JWT authentication is stateless, meaning that you don't need to store session data on the server. This promotes scalability and efficiency.&lt;br&gt;
2.&lt;strong&gt;Security:&lt;/strong&gt; JWTs can be cryptographically signed, rendering them tamper-proof. Your application's security is significantly enhanced.&lt;br&gt;
3.&lt;strong&gt;Cross-Origin Compatibility:&lt;/strong&gt; JWTs can be sent as HTTP headers, cookies, or query parameters, making them suitable for Single Page Applications (SPAs) and mobile apps.&lt;br&gt;
4.&lt;strong&gt;Simplified Front-end Integration:&lt;/strong&gt; Integrating JWTs into front-end frameworks like React, Angular, or Vue.js is straightforward, allowing for seamless user authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Integrating JWT Authentication in Ruby on Rails&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, let's walk through the process of implementing JWT authentication in your Ruby on Rails application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Adding Dependencies&lt;/strong&gt;&lt;br&gt;
To get started, you need to add the necessary gems to your Gemfile and run bundle install:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;gem 'jwt'&lt;br&gt;
gem 'bcrypt'&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;These gems are essential for working with JWT and securely storing passwords.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: User Model&lt;/strong&gt;&lt;br&gt;
Your existing User model plays a pivotal role. The model is the representation of users in your application, featuring attributes like email, password, and associations with other models.&lt;/p&gt;

&lt;p&gt;_class User &amp;lt; ApplicationRecord&lt;br&gt;
  has_secure_password&lt;/p&gt;

&lt;p&gt;# Additional attributes, associations, and validations can be defined here.&lt;br&gt;
end_&lt;/p&gt;

&lt;p&gt;The has_secure_password method in the User model is responsible for securely storing and validating user passwords.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Step 4: Authentication in ApplicationController&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;ApplicationController&lt;/strong&gt; is the heart of your JWT authentication. It oversees the process of authenticating users using JWT.&lt;/p&gt;

&lt;p&gt;_class ApplicationController &amp;lt; ActionController::API&lt;br&gt;
  before_action :authenticate_user&lt;/p&gt;

&lt;p&gt;private&lt;/p&gt;

&lt;p&gt;def authenticate_user&lt;br&gt;
    token = request.headers['Authorization'].to_s.split('Bearer ').last&lt;br&gt;
    if token.present?&lt;br&gt;
      decoded_token = JWT.decode(token, JWT_SECRET, true, algorithm: JWT_ALGORITHM)&lt;br&gt;
      user_id = decoded_token[0]['user_id']&lt;br&gt;
      @current_user = User.find(user_id)&lt;br&gt;
    else&lt;br&gt;
      @current_user = nil&lt;br&gt;
    end&lt;br&gt;
  end&lt;/p&gt;

&lt;p&gt;def current_user&lt;br&gt;
    @current_user&lt;br&gt;
  end&lt;br&gt;
end_&lt;/p&gt;

&lt;p&gt;In the ApplicationController, the before_action ensures that the authenticate_user method is executed before any controller action. The authenticate_user method is responsible for validating JWT tokens and setting the @current_user instance variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Users Controller&lt;/strong&gt;&lt;br&gt;
The Api::V1::UsersController takes care of user-related actions, such as user registration, login, and logout.&lt;/p&gt;

&lt;p&gt;_class Api::V1::UsersController &amp;lt; ApplicationController&lt;br&gt;
  # User registration logic&lt;br&gt;
  def create&lt;br&gt;
    # User registration logic&lt;br&gt;
  end&lt;/p&gt;

&lt;p&gt;# User login logic&lt;br&gt;
  def login&lt;br&gt;
    # User login logic&lt;br&gt;
  end&lt;/p&gt;

&lt;p&gt;# User logout logic&lt;br&gt;
  def logout&lt;br&gt;
    # User logout logic&lt;br&gt;
  end&lt;/p&gt;

&lt;p&gt;private&lt;/p&gt;

&lt;p&gt;def user_params&lt;br&gt;
    params.require(:user).permit(:email, :password, :password_confirmation)&lt;br&gt;
  end&lt;br&gt;
end&lt;br&gt;
_&lt;/p&gt;

&lt;p&gt;In this controller, the &lt;strong&gt;create&lt;/strong&gt; method handles user registration, &lt;strong&gt;login&lt;/strong&gt; manages user login, and &lt;strong&gt;logout&lt;/strong&gt; can be used for user logout functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JWT authentication offers a robust and secure solution for user authentication in Ruby on Rails applications. By following the steps outlined in this guide, you can establish a secure user registration and login process. JWTs, being stateless and efficient, have become the choice of many developers for ensuring secure user access in modern web applications.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>jwt</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Demystifying the MVC Architecture</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Fri, 03 Nov 2023 20:16:14 +0000</pubDate>
      <link>https://dev.to/amereen/demystifying-the-mvc-architecture-1l28</link>
      <guid>https://dev.to/amereen/demystifying-the-mvc-architecture-1l28</guid>
      <description>&lt;p&gt;&lt;strong&gt;What Is MVC?&lt;/strong&gt;&lt;br&gt;
MVC stands for Model-View-Controller, a design pattern used in software development, particularly in web application frameworks like Ruby on Rails divides an application into three interconnected components.&lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Model&lt;/strong&gt;: The Model represents the application's data and business logic. It encapsulates the rules and behavior governing the application's functionality. For instance, in a blog application, the Model would handle data related to blog posts, users, and comments.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;View&lt;/strong&gt;: The View is responsible for rendering the data to the user. It displays the information from the Model to the user in a human-readable format. In our blog example, the View would handle how the blog posts, user profiles, and comments are presented to the user on a web page.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Controller&lt;/strong&gt;: The Controller acts as an intermediary between the Model and the View. It receives user input, processes it, and updates the Model or View accordingly. In our blog application, the Controller would handle user actions like creating a new blog post, updating a user's profile, or posting a comment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The MVC Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To understand MVC better, let's take a quick tour of how these components work together:&lt;/p&gt;

&lt;p&gt;1.A user interacts with the application, say by clicking a "Create New Post" button.&lt;/p&gt;

&lt;p&gt;2.The user's action is captured by the Controller, which then decides how to proceed.&lt;/p&gt;

&lt;p&gt;3.The Controller may instruct the Model to create a new blog post, save it to the database, and return the updated data.&lt;/p&gt;

&lt;p&gt;4.The Controller then chooses an appropriate View to display the result to the user. It might render a page showing the newly created post.&lt;/p&gt;

&lt;p&gt;5.The View, equipped with data from the Model, presents the information to the user.&lt;/p&gt;

&lt;p&gt;This separation of concerns is the core principle of MVC. It makes applications more organized, easier to maintain, and enables multiple Views for a single Model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of MVC&lt;/strong&gt;&lt;br&gt;
Understanding MVC's advantages is crucial:&lt;/p&gt;

&lt;p&gt;Modularity: MVC promotes a modular design. You can make changes to one component without affecting the others. For instance, you can update the View's appearance without altering the underlying Model or Controller.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Imagine you have a toy car. In this analogy:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The &lt;strong&gt;Model&lt;/strong&gt; is like the engine and mechanical parts inside the car.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;The &lt;strong&gt;View&lt;/strong&gt; is like the car's appearance, color, and design.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;The &lt;strong&gt;Controller&lt;/strong&gt; is like the driver who operates the car.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Now, if you want to change the color of your toy car (View), you can do that without altering the engine (Model) or the way you drive the car (Controller). This separation of concerns allows you to make changes to one part without disrupting the others.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Reusability: Components are reusable in different parts of the application. You can use the same Model to display data in various Views or have one Controller handle different user actions.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Suppose you have another toy, a toy boat. This time:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Model&lt;/strong&gt; for the boat includes the engine and the mechanical parts.&lt;br&gt;
The &lt;strong&gt;Controller&lt;/strong&gt; for the boat includes the operator's control mechanisms._&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Now, if the engine (Model) in your toy car is well-designed and efficient, you can also use it in your toy boat without having to create a new engine from scratch. Similarly, if the operator's control (Controller) for the car works smoothly, you can adapt it for the boat.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Collaboration: Multiple developers can work on different parts of the application simultaneously. A designer can focus on the View, a database expert on the Model, and a logic programmer on the Controller.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MVC is a powerful and widely adopted architectural pattern that has stood the test of time in web development. By dividing your application into Models, Views, and Controllers, you can create well-structured, maintainable, and flexible applications. The next time you embark on a web development journey, remember the MVC pattern as your trusty guide.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Methods In Ruby</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Tue, 04 Apr 2023 05:59:39 +0000</pubDate>
      <link>https://dev.to/amereen/methods-in-ruby-4g5a</link>
      <guid>https://dev.to/amereen/methods-in-ruby-4g5a</guid>
      <description>&lt;p&gt;Ruby is a popular object-oriented programming language that is widely used for developing web applications and other software. It is known for its simplicity and ease of use, making it a great choice for beginners and experienced programmers alike. One of the key features of Ruby is the availability of numerous methods that can be used to accomplish various tasks. In this blog post, we will discuss some of the most useful methods in Ruby and how they can be used.&lt;/p&gt;

&lt;p&gt;1.each&lt;br&gt;
 The each method is used to iterate over a collection and perform an action on each element. It takes a block of code as an argument and executes that block once for each element in the collection. For example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F828jtgbpehk31v8z1wv2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F828jtgbpehk31v8z1wv2.png" alt="Image description" width="532" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxubju4hlz7utjhfx0yp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxubju4hlz7utjhfx0yp.png" alt="Image description" width="236" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;map
The map method is used to transform each element in a collection based on a block of code. It returns a new collection with the transformed elements. For example:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyy6226f7ixqh3taft46a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyy6226f7ixqh3taft46a.png" alt="Image description" width="800" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp0ujxjycodraxuvo305n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp0ujxjycodraxuvo305n.png" alt="Image description" width="604" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;select
The select method is used to filter a collection based on a block of code. It returns a new collection containing only the elements that meet the criteria specified in the block. For example:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F769jt75wh1gch1115bme.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F769jt75wh1gch1115bme.png" alt="Image description" width="800" height="383"&gt;&lt;/a&gt;&lt;br&gt;
This will output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftrn306tx4thhaa1i0osy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftrn306tx4thhaa1i0osy.png" alt="Image description" width="306" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;reduce
The reduce method is used to combine all the elements in a collection into a single value. It takes a block of code as an argument that specifies how to combine the elements. For example:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9zrcijyxo0drf42wer3e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9zrcijyxo0drf42wer3e.png" alt="Image description" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxkwvwsmwybkkpga9xba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxkwvwsmwybkkpga9xba.png" alt="Image description" width="611" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, the reduce method starts with an accumulator value of 0 and adds each element in the array to the accumulator.&lt;/p&gt;

&lt;p&gt;These are just a few of the many methods available in Ruby. By using these methods, you can write concise and expressive code that is easy to read and maintain. As you become more familiar with Ruby, you will discover even more methods that can help you write efficient and effective code.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Props</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Wed, 18 Jan 2023 03:01:24 +0000</pubDate>
      <link>https://dev.to/amereen/props-4b8</link>
      <guid>https://dev.to/amereen/props-4b8</guid>
      <description>&lt;p&gt;Data is passed from a parent component to a child component in React using props, which is short for properties. Similar to how HTML attributes are used to set the properties of an HTML element, props are supplied as attributes to the child component.&lt;br&gt;
Here's an example of passing props to a child component:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ged3wpzcxpjm27ezm1h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ged3wpzcxpjm27ezm1h.png" alt="Image description" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, the ParentComponent is passing a message prop with the value "Hello World" to the ChildComponent. The ChildComponent is then able to access the prop by destructuring the props object and extracting the message property. The child component then render the message prop into the div.&lt;br&gt;
You can also pass multiple props to a child component, like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuqobhvb3niar76dbb372.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuqobhvb3niar76dbb372.png" alt="Image description" width="800" height="69"&gt;&lt;/a&gt;&lt;br&gt;
Here, the child component can access these props like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbqyjvnw0yz8xc0moc2b1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbqyjvnw0yz8xc0moc2b1.png" alt="Image description" width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's also possible to pass functions as props and allow the child component to interact with the parent component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6hrnlnffsgzhim8wwcaq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6hrnlnffsgzhim8wwcaq.png" alt="Image description" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then the child component can use it like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gruhx5f5rt8rylocezh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gruhx5f5rt8rylocezh.png" alt="Image description" width="800" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's important to note that React follows one way data flow, meaning that data should flow from the parent component to child component and not the other way around. Thus, child component can't change the props passed to them, they can only use them to render or pass them to other child component.&lt;/p&gt;

&lt;p&gt;When props are passed down to multiple levels of child components in a React application, it's often referred to as "prop drilling." This means that props are passed down through multiple levels of the component tree, from a parent component to a child component, and then from that child component to its own child component, and so on.&lt;/p&gt;

&lt;p&gt;Here's an example of prop drilling:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Finh864ljuno8ovk0zo1k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Finh864ljuno8ovk0zo1k.png" alt="Image description" width="800" height="719"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, the ParentComponent passes a message prop to the Child1 component. Child1 component then passes the same prop to its own child component Child2, which in turn passes the same prop to Child3. The Child3 component is then able to access the prop and use it to render the message.&lt;/p&gt;

&lt;p&gt;Prop drilling can become tedious as the component tree grows and it becomes more difficult to trace where the props are being passed and how they are being used. In such cases, it's recommended to use context or higher-order component to avoid excessive prop drilling.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>react</category>
      <category>html</category>
    </item>
    <item>
      <title>CreateContext</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Wed, 18 Jan 2023 02:35:45 +0000</pubDate>
      <link>https://dev.to/amereen/createcontext-2api</link>
      <guid>https://dev.to/amereen/createcontext-2api</guid>
      <description>&lt;p&gt;Developers can construct a context object to use to transport data across a component tree using the CreateContext method supplied by the React library in JavaScript, eliminating the need to manually pass props down at each level. Data sharing across components that are not directly connected in the component tree is made possible by this.&lt;br&gt;
Here's an example of how to create a context object:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F33hyrmrsck3df8l97myh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F33hyrmrsck3df8l97myh.png" alt="Image description" width="800" height="135"&gt;&lt;/a&gt;&lt;br&gt;
The createContext method takes an optional default value as its argument, which will be used as the initial value for the context if a Provider is not present further up the component tree.&lt;/p&gt;

&lt;p&gt;Once the context is created, it can be consumed by any component in the tree using the useContext hook or the Context.Consumer component.&lt;/p&gt;

&lt;p&gt;Here's an example of how to use the context in a component:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffuctyk9nzo5v9co8bqg6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffuctyk9nzo5v9co8bqg6.png" alt="Image description" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Context.Consumer component is a part of the React library. It is used to access the context data that has been provided by a Context.Provider component. The Context.Consumer component takes a single function as its child, which is called with the current context value. The function should return a React element, which will be rendered with the current context data.&lt;/p&gt;

&lt;p&gt;For example, in the following code snippet, the ThemeContext.Consumer component is used to access the theme value provided by the ThemeContext.Provider component. The function passed as a child to the ThemeContext.Consumer component is called with the current theme value, and the returned element is rendered with the current theme.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbgn6p2uajggbn15vdgqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbgn6p2uajggbn15vdgqx.png" alt="Image description" width="800" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To provide the context with a value, you can use the Context.Provider component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvq2v7eef8o09ezecr5tw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvq2v7eef8o09ezecr5tw.png" alt="Image description" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, the context value for  MyComponent component will be "Hello World." The context will also be used by any components lower down the tree that consume it. It is important to remember that you can use the context's Provider anywhere in the component tree, it doesn't need to be the parent of the component that uses the context.&lt;/p&gt;

&lt;p&gt;You could also update the context value by using the state and setState Hooks&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5zlab7n51ns89uvapzwa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5zlab7n51ns89uvapzwa.png" alt="Image description" width="800" height="673"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, the value of the context will change to "New Value" when the button is clicked and all the components that are consuming the context will receive the new value.&lt;/p&gt;

&lt;p&gt;To sum up, createContext is a powerful tool that allows data to be shared between components that are not directly connected in the component tree, it can be consumed with useContext or Context.Consumer and provided with Context.Provider and it allows the context value to be updated with state and setState hooks.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Call Back Functions ()</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Thu, 13 Oct 2022 05:09:22 +0000</pubDate>
      <link>https://dev.to/amereen/call-back-functions--fb0</link>
      <guid>https://dev.to/amereen/call-back-functions--fb0</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;What is a callback in JavaScript?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;A function passed as an argument to another function is known as a callback&lt;/em&gt;. JavaScript considers functions to be objects. Functions can therefore return other functions and accept functions as arguments. Higher order functions are those that perform this. A callback function is any function that receives an argument. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do you create a callback function in JavaScript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here I have created an easy example. A message has to be logged to the console, although it should be there after three seconds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3wvy8dvsbbwis0hu2lhj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3wvy8dvsbbwis0hu2lhj.png" alt="Image description" width="800" height="398"&gt;&lt;/a&gt;&lt;br&gt;
A built-in JavaScript method called "setTimeout" calls a function or evaluates an expression after a predetermined amount of time (in milliseconds). As a result, after 3 seconds, the "message" function gets invoked in this case. 1000 milliseconds make up one second. The message function is an example of a callback function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Callback as an arrow&lt;/strong&gt; (=&amp;gt;) &lt;br&gt;
You can also write callback function as an ES6 arrow function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd57vjo1a3f050vco8s6a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd57vjo1a3f050vco8s6a.png" alt="Image description" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do we need a callback function?&lt;/strong&gt;&lt;br&gt;
Because JavaScript is a synchronous language, its code would execute in a top-to-bottom order. We frequently get across situations where we need our code to execute after a certain condition has been met, but JavaScript synchronous setup makes this impossible. And this is when a callback is required. Callbacks allow us to run JavaScript asynchronously and ensure that our condition is met before any code is executed. Callback functions are necessary because many JavaScript actions are asynchronous, which means they don't actually stop the program or a function from running until they are finished. Rather, it will operate in the background as the other code is run.&lt;br&gt;
The main objective of a callback is to run code in response to an event. These actions, like typing or mouse clicks, may have been initiated by the user. You can tell your application to "run this code every time the user clicks a key on the keyboard" by using a callback.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwj3xlta0pl74eyglvtv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwj3xlta0pl74eyglvtv.png" alt="Image description" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Asynchronous Callback Function&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
We will start by defining an asynchronous activity. Let's say you need to go to the salon to get your hair dyed and then go to the bank to withdraw some money. You first go to the salon and have the stylist add hair dye to your hair, which will take approximately 20 minutes. The finished result will take an hour. You decide to drive 20 minutes to the bank to make the withdrawal rather than spending an hour sitting on a chair waiting to have the dye washed out. Realizing that you still have some time, you quickly stop by a coffee shop to pick up a few things. Finally you go back to the salon to have your hair washed out and styled. In the above example you continued to do other things as hair dye was doing its job. This is the main purpose of asynchronous activity. One program execution does not happen sequentially to other program executions. JavaScript is a single threaded language, if a task is taking long time for example downloading some files. All the other tasks mentioned after the downloading code will be performed during that time. We use Asynchronous JavaScript(Callbacks,Promises and Async/Await) for executing async commands in a systematic order.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foogy8fm6tqaith9cw9rb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foogy8fm6tqaith9cw9rb.png" alt="Image description" width="520" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjl6aw2sukuu4htrv1zr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjl6aw2sukuu4htrv1zr.png" alt="Image description" width="558" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here in the console you can see start and end executed first, mid executed after 3 seconds.&lt;br&gt;
&lt;strong&gt;_&lt;br&gt;
Callbacks in Array Functions_&lt;/strong&gt;&lt;br&gt;
The array operations map(), reduce(), filter(), forEach(), and others are probably familiar to you. These functions all make use of callbacks. Each of them will call the callback method after iterating through an array of items. Down below is a forEach example ().&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8gq5h4v5ilwwbve0zmk2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8gq5h4v5ilwwbve0zmk2.png" alt="Image description" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrap it up&lt;/strong&gt;&lt;br&gt;
A callback is a function that isn’t immediately executed, but it is passed to another function as an argument and then it is 'called back' at a later point when the conditions are met.&lt;br&gt;
Depending on the use case, callback functions can be used to inform the caller. Callbacks are also used to execute specific actions in response to the success or failure of other tasks.&lt;br&gt;
Callbacks play a crucial role in JavaScript. The flow and usage can initially seem difficult, but hopefully this blog post have made it easier!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating a JavaScript project for a single page application</title>
      <dc:creator>Amereen</dc:creator>
      <pubDate>Thu, 13 Oct 2022 04:01:40 +0000</pubDate>
      <link>https://dev.to/amereen/creating-a-javascript-project-for-a-single-page-application-388f</link>
      <guid>https://dev.to/amereen/creating-a-javascript-project-for-a-single-page-application-388f</guid>
      <description>&lt;p&gt;Before I began my first Single Page Application project in JavaScript, I had a limited understanding of what an SPA (Single Page Application) was and how much information could be accessed on a single page.Single page application development can be a pretty inventive process, a lot of thought goes into figuring out how to add functionality to build a project especially your first project. I was overwhelmed when I first started building my project, so I kept reading the instructions and making notes about ideas I wanted to incorporate. But the very first google search I did regarding my project was on (SPA) a "Single Page Application which is a web app that loads only a single web document and then updates the body content of that single document via JavaScript APIs such as XMLHttpRequest and Fetch when different content is to be shown."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fejfd0j3gj3uonwr7u440.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fejfd0j3gj3uonwr7u440.png" alt="Image description" width="800" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So basically this means that there are no redirects to other pages and that you are working with just one HTML file. In order to style your project, you could have only one HTML file, one JS file, and one CSS file.&lt;/p&gt;

&lt;p&gt;I first started building my basic HTML skeleton, I created div container which I use to append my contents(content stored in other tags) which I created a function for.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F92ydaawpgrrbqvb3glrg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F92ydaawpgrrbqvb3glrg.png" alt="Image description" width="763" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I then Created a function in my Js file, in that function I created new elements using the "document.createElement()"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fecspc9qt25jud56hsagw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fecspc9qt25jud56hsagw.png" alt="Image description" width="800" height="324"&gt;&lt;/a&gt;&lt;br&gt;
In the function that I have created I append all the new elements created to my div container, using the .append() method.&lt;br&gt;
I also, added "innerText" to the variable of my created elements as well as dot notations to refer to the content from my API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjy8mwqon6cpjfasjsh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjy8mwqon6cpjfasjsh5.png" alt="Image description" width="800" height="550"&gt;&lt;/a&gt;&lt;br&gt;
There are numerous more forms of SPA that may be built. Even though working with a SPA can often be restrictive, there are ways to get around it and still have fun.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
