<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Niyi0904</title>
    <description>The latest articles on Forem by Niyi0904 (@niyi0904).</description>
    <link>https://forem.com/niyi0904</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%2F1173436%2F853f58ce-766d-4880-8f81-48387ab1c23d.png</url>
      <title>Forem: Niyi0904</title>
      <link>https://forem.com/niyi0904</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/niyi0904"/>
    <language>en</language>
    <item>
      <title>Context API</title>
      <dc:creator>Niyi0904</dc:creator>
      <pubDate>Mon, 01 Jul 2024 16:01:03 +0000</pubDate>
      <link>https://forem.com/niyi0904/context-api-2268</link>
      <guid>https://forem.com/niyi0904/context-api-2268</guid>
      <description>&lt;p&gt;The Context API in React provides a way to pass data through the component tree without the need to pass props down manually at every level. The global state created using context API can be accessed by any component within the tree, regardless of how close they are to one another in the hierarchy.&lt;/p&gt;

&lt;p&gt;There are cases where we want to pass down data to a child component, and we have components in between the child component that needs such data and the parent component. Rather than do a prop drilling ( passing prop down to component that don't need it to get ut to components that need it )we can use a context API&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to Context API ?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To avoid prop drilling which is a bad practice &lt;/li&gt;
&lt;li&gt;To avoid use a separate API for state management.
Usually we will use library like Redux to manage our state,  but in a medium or small size application context API would be the best choice.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;How do we integrate Context API?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a file named context ( or whatever you want )&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In that file import createContext from react like so; &lt;br&gt;
Import { createContext, useContext} from 'react';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a context:&lt;br&gt;
const MyContext =&lt;br&gt;
createContext();&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a provider:&lt;br&gt;
const MyProvider = ({ children }) =&amp;gt; {&lt;br&gt;
const [state, setState] = useState(initialState);&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;return (&lt;br&gt;
    &lt;br&gt;
      {children}&lt;br&gt;
    &lt;br&gt;
  );&lt;br&gt;
};&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Wrap your app with the provider in your index.JS file:


&lt;/li&gt;
&lt;li&gt;Create an exported variable with that wraps your context with useContext making your context available to any component:
const UseStateContext = () =&amp;gt; useContext(MyContext);
To use your created context in a file &lt;/li&gt;
&lt;li&gt;&lt;p&gt;Import your export context variable (UseStateContext) into your desired file. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use it either by destructuring e.g&lt;br&gt;
Const {state, setState} = UseStateContext();&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now you can use state and setState in your component &lt;/p&gt;

&lt;p&gt;By following these steps, you have successfully integrated the Context API in your React application, allowing you to share state and functionality across components without prop drilling.&lt;/p&gt;

&lt;p&gt;Note: Make sure to import the &lt;code&gt;React&lt;/code&gt; and &lt;code&gt;useContext&lt;/code&gt; hook from the &lt;code&gt;react&lt;/code&gt; package, and the &lt;code&gt;useState&lt;/code&gt; hook from the &lt;code&gt;react&lt;/code&gt; package or a compatible library like &lt;code&gt;react-hooks&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>website</category>
    </item>
    <item>
      <title>React Vs Angular</title>
      <dc:creator>Niyi0904</dc:creator>
      <pubDate>Mon, 01 Jul 2024 15:22:47 +0000</pubDate>
      <link>https://forem.com/niyi0904/react-vs-angular-30e4</link>
      <guid>https://forem.com/niyi0904/react-vs-angular-30e4</guid>
      <description>&lt;p&gt;Firstly I would like to introduce the frameworks and their popularity &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REACT&lt;/strong&gt; &lt;br&gt;
React is a popular JavaScript library for building user interfaces created in 2011 by Jordan walker and it is managed by Facebook &lt;/p&gt;

&lt;p&gt;It is also important to know react was released as an open source library, and it was firstly named faxJS. &lt;/p&gt;

&lt;p&gt;Some of the key concepts of React are as follows &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Component-based architecture:&lt;/strong&gt; React uses a component-based architecture, where applications are broken down into small, reusable components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JSX&lt;/strong&gt;: React uses JSX, a syntax extension that allows you to write HTML-like code in your JavaScript files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Virtual DOM&lt;/strong&gt;: React uses a virtual DOM (a lightweight in-memory representation of the real DOM) to optimize rendering and updating of components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;One-way data binding:&lt;/strong&gt; React uses a one-way data binding approach, where components only receive updates from their parents, not the other way around.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;State and props:&lt;/strong&gt; Components manage their own state, and receive props from their parents.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hooks:&lt;/strong&gt; React provides hooks, a way to use state and other React features without writing a class component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Popular libraries and tools:&lt;/strong&gt; React has a large ecosystem of libraries and tools, including Redux, React-router-dom, React-scroll and Webpack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Wide adoption:&lt;/strong&gt; React is widely adopted in the industry, and is used by companies like Facebook, Instagram, and Netflix. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some advantages of using React include: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Efficient rendering:&lt;/strong&gt; React's virtual DOM and one-way data binding approach make it efficient for rendering and updating components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy to learn:&lt;/strong&gt; React has a relatively low barrier to entry, and is easy to learn for developers familiar with JavaScript and HTML/CSS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible and customizable:&lt;/strong&gt; React can be used for a wide range of applications, from small widgets to complex enterprise applications. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some potential Disadvantages of using React include: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Steep learning curve for advanced topics:&lt;/strong&gt; While React is easy to learn for basic usage, some advanced topics like hooks and context can be challenging to master.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Not a full-featured framework:&lt;/strong&gt; React is a library, not a full-featured framework like Angular or Vue. This means you may need to use additional libraries and tools to build a complete application.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;ANGULAR&lt;/strong&gt; &lt;br&gt;
Angular is a popular JavaScript framework for building web applications. It was created by Google in the year 2010 &lt;/p&gt;

&lt;p&gt;Here are some key points about Angular: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;**Full-featured framework: **Angular is a complete framework that includes everything you need to build complex web applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modular architecture:&lt;/strong&gt; Angular uses a modular architecture, where applications are broken down into small, reusable modules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Components:&lt;/strong&gt; Angular uses components, which are similar to React components, to build user interfaces.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Templates:&lt;/strong&gt; Angular uses HTML templates, which are compiled into JavaScript code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependency injection:&lt;/strong&gt; Angular uses dependency injection to manage dependencies between components and services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Services:&lt;/strong&gt; Angular provides services, which are singletons that can be used to share data and functionality across components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Routing:&lt;/strong&gt; Angular provides a built-in routing system for navigating between views.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Forms:&lt;/strong&gt; Angular provides a built-in forms system for handling user input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Observables:&lt;/strong&gt; Angular uses observables, which are a way to handle asynchronous data streams.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TypeScript:&lt;/strong&gt; Angular is built on top of TypeScript, which provides type checking and other features. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some advantages of using Angular include: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Comprehensive framework:&lt;/strong&gt; Angular provides everything you need to build complex web applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Large community:&lt;/strong&gt; Angular has a large and active community, with many resources available.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enterprise-ready:&lt;/strong&gt; Angular is widely used in enterprise environments, and is well-suited for large-scale applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Opinionated: Angular has a strong opinion on how applications should be structured, which can help guide development. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some potential Disadvantages of using Angular: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Steep learning curve:&lt;/strong&gt; Angular has a complex architecture and a lot of features, which can make it challenging to learn.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verbose:&lt;/strong&gt; Angular requires a lot of boilerplate code, which can make it feel verbose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Not as flexible as React:&lt;/strong&gt; Angular has a more rigid architecture than React, which can make it harder to adapt to certain use cases.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let see some diffence between React and Angular &lt;/p&gt;

&lt;p&gt;Here is a table comparing React and Angular: &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;React&lt;/th&gt;
&lt;th&gt;Angular&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Architecture&lt;/td&gt;
&lt;td&gt;Library, component-based&lt;/td&gt;
&lt;td&gt;Framework, modular&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Components&lt;/td&gt;
&lt;td&gt;Functional/Class, JSX&lt;/td&gt;
&lt;td&gt;Components with templates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;State Management&lt;/td&gt;
&lt;td&gt;Props, State, Redux/MobX&lt;/td&gt;
&lt;td&gt;Services, Observables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Templates&lt;/td&gt;
&lt;td&gt;JSX, JavaScript-based&lt;/td&gt;
&lt;td&gt;HTML templates, Template-driven&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Learning Curve&lt;/td&gt;
&lt;td&gt;Steeper, JavaScript-focused&lt;/td&gt;
&lt;td&gt;Gentler, HTML/CSS-focused&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Virtual DOM, efficient updates&lt;/td&gt;
&lt;td&gt;Real DOM, efficient change detection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ecosystem&lt;/td&gt;
&lt;td&gt;Large, diverse, widely adopted&lt;/td&gt;
&lt;td&gt;Large, strong backing from Google&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now, let see some similarities between React and Angular &lt;br&gt;
Here is a table highlighting some similarities between React and Angular:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Similarity&lt;/th&gt;
&lt;th&gt;React&lt;/th&gt;
&lt;th&gt;Angular&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Component-based architecture&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use of components&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Support for one-way data binding&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use of services for global state management&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Support for server-side rendering&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Large and active community&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Wide adoption in industry&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Support for desktop and mobile applications&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Extensive library of third-party tools and libraries&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;From the developer survey&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%2F44mlez65jaoqcwxszwmp.jpg" 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%2F44mlez65jaoqcwxszwmp.jpg" alt="Image description" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;React takes the lead over Angular. &lt;/p&gt;

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