<?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 Rohan Mathew alex on Medium]]></title>
        <description><![CDATA[Stories by Rohan Mathew alex on Medium]]></description>
        <link>https://medium.com/@rohanmathewalex?source=rss-9d2a15870f58------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Nlo9i8xR2okEh6rYqqadAA.jpeg</url>
            <title>Stories by Rohan Mathew alex on Medium</title>
            <link>https://medium.com/@rohanmathewalex?source=rss-9d2a15870f58------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 13:26:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rohanmathewalex/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[Mastering State Management with Redux: Actions, Store, and Reducers Explained]]></title>
            <link>https://medium.com/@rohanmathewalex/mastering-state-management-with-redux-actions-store-and-reducers-explained-79c1a4386a53?source=rss-9d2a15870f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/79c1a4386a53</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[rect]]></category>
            <dc:creator><![CDATA[Rohan Mathew alex]]></dc:creator>
            <pubDate>Sat, 18 May 2024 06:01:09 GMT</pubDate>
            <atom:updated>2024-05-18T06:01:09.898Z</atom:updated>
            <content:encoded><![CDATA[<p>After reading this article, you will be able to: Explain the essential concepts of Redux. And describe <strong>Actions</strong>, S<strong>tore</strong>, and <strong>Reducers</strong>.</p><p>Let’s learn what is the basic principle behind the working of Redux.</p><h3>Basic principles of Redux</h3><ul><li>Redux offers a centralized state management system in your application library. The state of your application is managed by a single store and not by individual components.</li><li>A component’s properties should be considered immutable. With Redux, when a user interacts with a component in an application, the Action updates the entire application’s state. This, in turn, triggers a re-render of the component, thereby updating that component’s properties These properties display the result to the user.</li></ul><p><strong>Structure: </strong>An action is a plain JavaScript object. Apart from the mandatory type field, it can include other fields with information about what happened.</p><pre>const action = {<br>  type: &#39;ADD_TODO&#39;,<br>  payload: {<br>    text: &#39;Learn Redux&#39;<br>  }<br>};</pre><p><strong>Action Creators: </strong>These are functions that create and return an action object. They encapsulate the creation of actions, making the code more readable and manageable.</p><pre>function addTodo(text) {<br>  return {<br>    type: &#39;ADD_TODO&#39;,<br>    payload: {<br>      text<br>    }<br>  };<br>}</pre><h3>Redux Concept</h3><p>The Redux elements that are involved in updating the component properties are:</p><ul><li><strong>Actions</strong> are what your app can do.</li><li><strong>Store</strong>, that is the singular location and authoritative source of the app state.</li><li><strong>Reducers</strong>, that are actions which return the new state</li></ul><pre>function todos(state = [], action) {<br>  switch (action.type) {<br>    case &#39;ADD_TODO&#39;:<br>      return [<br>        ...state,<br>        {<br>          text: action.payload.text,<br>          completed: false<br>        }<br>      ];<br>    default:<br>      return state;<br>  }<br>}</pre><h3>What are Actions?</h3><ul><li>So, when an event is fired from any view by selecting a radio button, clicking a checkbox, or clicking a button it is called an action.</li><li>Actions are JSON objects that contain information about changes that need to be made to the state.</li><li>Actions are produced by functions called Action creators. It is a pure object created to store the information of the user’s event, and it describes a state change.</li><li>It contains the type of Action, time of occurrence, and which states it aims to change.</li></ul><h3>Behavior of actions</h3><h4>Actions are:</h4><p>. Actions can be dispatched by various parts of your application, and they are received by the store. They are payloads of information that send data from application to store.</p><p>. They are plain JavaScript objects that describe WHAT happened, but do not describe HOW the app state will change.</p><p>. Actions are sent to your store instance whenever you want to update the state of your application.</p><p>. The rest is handled by the Reducers. Redux requires all Action objects to contain a type field. This field is used to describe what kind of Action is dispatched and is a constant that you export from a file. All other fields in the Action object are optional.</p><h3>Store</h3><ul><li>The current Redux application state lives in an object that is called the <strong><em>store</em></strong>.</li><li>There is a single Store per Redux application. It is an object, not a class, and besides your application’s state, it contains functions and other objects. In addition, a Store can dispatch and receive actions.</li><li>However, the Store does not perform any changes to the application state, which is done by the Reducers.</li><li>You can subscribe to listen to events whenever the Store updates. In a non-React app, you might use this subscription to update the UI.</li><li>The application state in Redux is in the form of a JavaScript Object and is often referred to as the ‘state tree’.The Store holds the entire application list in the form of the ‘state tree’. You can add any values to the ‘state tree’ in the Store, and you can nest them as required.</li></ul><h3>Reducers</h3><p>. Whenever you dispatch an Action to your store, the action is passed to the Reducer.</p><p>. The reducer then makes the appropriate changes to the state.</p><p>. Reducers are pure functions that receive the current state and an Action object and return a new state with the actions performed. In other words, they are used to recalculate the new application state or at least, a part of it.</p><p>. It acts as an event listener which handles events based on the accepted event type. It reads the payloads from the Action and then updates the Store via the state accordingly.</p><h3>. The Reducer function takes two parameters; the previous app state and the Action being dispatched. It returns the new app state.</h3><h3>Summary</h3><p>. The Redux elements that are involved in updating of the component properties are: Actions, Store, and Reducers.</p><p>. Actions are JSON objects that contain information about changes that need to be made to the state.</p><p>. The current Redux application state lives in an object that is called the Store.</p><p>. Reducers are pure functions that receive the current state and an Action object and return a new state with the actions performed.</p><p>. And you can subscribe to listen to events whenever the Store updates.<br>Redux requires all Action objects to contain a type field.</p><p>. This field is used to describe what kind of Action is dispatched and is a constant that you export from a file. All other fields in the Action object are optional.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79c1a4386a53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering React 18 Hooks: Simplify and Supercharge Your Functional Components]]></title>
            <link>https://medium.com/@rohanmathewalex/mastering-react-18-hooks-simplify-and-supercharge-your-functional-components-e79d31324029?source=rss-9d2a15870f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/e79d31324029</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[react-18-new-features]]></category>
            <dc:creator><![CDATA[Rohan Mathew alex]]></dc:creator>
            <pubDate>Fri, 17 May 2024 05:18:00 GMT</pubDate>
            <atom:updated>2024-05-17T05:18:00.637Z</atom:updated>
            <content:encoded><![CDATA[<p>Hooks provide a way to write functional components with the same capabilities as class components. Namely, you can access a component’s state using hooks with function components. The component preserves its state when it updates and re-renders. So now, function components provide the same functionality as class components with less complexity in the code.</p><p>As the name suggests, they enable you to hook into React’s state and lifecycle features from function components. You can even write customized hooks. You can write a custom hook for multiple components instead of duplicating code from one component to another.</p><h3>Advantages of using Hooks</h3><p>Advantages of using hooks include easier-to-read code, your code chunks become more manageable in size. Hooks help to optimize your code, enabling you to write code producing complex behaviors in the UI. They simplify your code. Hooks help you handle events and subsequent logic without classes. Hooks also provide a performance boost to your components. Now let’s discuss some best practices when using hooks.</p><p>You can only use hooks exclusively with function components. You must call a hook at the top level of a component tree. In other words, you cannot call hooks within child components. You cannot call a hook from a normal JavaScript function. You cannot call hooks inside loops, conditional statements, or nested functions. Regarding versioning, hooks require the Node.js version 6 JavaScript platform.</p><p>In addition, they use the node package manager (NPM) version 5.2 or higher. You should use the <em>create-react-app</em> tool to set up your React app. It simplifies configuration and the need for multiple build tools and automatically optimizes your app. Let’s explore some of the most commonly used hooks.</p><p>The useState hook allows you to access the state of the component in your function component. The useEffect hook manages side effects such as document changes and HTTP requests. You will use it if you need to fetch data from a database.</p><p>The<strong><em> useContext</em></strong> hook manages context changes and provides access to a context.</p><p>The<strong><em> useReducer </em></strong>hook manages Redux state changes.</p><p>Like a light form of Redux, this hook provides a dispatch function and a state while taking a reducer and an initial state.</p><blockquote>Custom React hooks let you add unique functionality to your React applications. You name custom with ‘use’ as a prefix.</blockquote><p>For example, you could create custom hooks named <strong><em>useLocalStorage</em></strong> or <strong><em>useAuthentication</em></strong>. A custom hook is a new composition of one or multiple hooks. Since you can treat hooks as functions, they have the same features. You can reuse and combine them as needed.</p><pre>import React , {useState} from &#39;react&#39;;<br>function CntApp() {<br>//Declare a new state variable  &quot;Ccount&quot;<br>const [count, setCount] = useState(0);<br>return(<br>&lt;div&gt;<br>&lt;p&gt;You clicked {count} many times&lt;/p&gt;<br>&lt;button onClick={() =&gt; setCount(count+1)}&gt; Click Me &lt;button/&gt;<br>&lt;/div&gt;<br>)<br>}<br>export default cntApp</pre><p>In this code example, this code imports the useState hook to access the component’s local state. This hook returns and assigns values with a destructed array. The current count state is the first array element, and the second variable sets the count, allowing you to make updates. The initial count is passed as a parameter in the useState hook function. After that, you call this function from an event handler to utilize it.</p><h3>Summary</h3><ul><li>In this article you learned that hooks provide function components with the same capabilities as class components.</li><li>Hooks enable you to write simpler, more readable, and a lesser amount of code, providing more complex behaviors and improving performance.</li><li>You must call hooks at the top of a tree and cannot call them from regular or nested functions or inside loops or conditions.</li><li>Standard hooks include useState, useEffect, useContext, and useReducer</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e79d31324029" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering React Component Testing: Strategies, Tools, and Best Practices]]></title>
            <link>https://medium.com/@rohanmathewalex/mastering-react-component-testing-strategies-tools-and-best-practices-2c7595134e79?source=rss-9d2a15870f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c7595134e79</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[react-testing-library]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[react-testing]]></category>
            <dc:creator><![CDATA[Rohan Mathew alex]]></dc:creator>
            <pubDate>Sat, 11 May 2024 05:18:56 GMT</pubDate>
            <atom:updated>2024-05-11T05:18:56.259Z</atom:updated>
            <content:encoded><![CDATA[<p>Testing is a line-by-line review of how your code will be executed. It can be a suite of tests comprising bits of code to verify the error-free execution of the application.</p><h4>Advantages</h4><ul><li>Prevent Unexpected Regression It requires writing more code, debugging, and maintaining.</li><li>Prevent Unexpected regression, It requires writing of more code, debugging, and maintaining.</li><li>Allows focus on current task causes integration rejection due to non-critical failures</li><li>Allows modular construction of applications.</li><li>Reduces need for manual verification</li></ul><h4>Why test React components</h4><p>Testing of React components:</p><ul><li>Ensures application will work as intended.</li><li>Verifies the code runs error-free.</li><li>Tests functionality by replicating the actions of end users.</li><li>Validates that any updates done do not affect the working of the overall application.</li><li>It prevents regression, that is, the reappearance of a previous fixed bug.</li></ul><h4>Approaches of React Component Testing</h4><ul><li>Render component trees in a simple test environment and assert their output</li><li>Run the application in a realistic browser environment to do end-to-end testing.</li></ul><h4>Phases of React component testing</h4><ul><li>Arrange → During this phase, the component properties are prepared.</li><li>Act → In this phase, the component needs to render its DOM to the user interface. It then registers any user actions or events that may trigger programmatically</li><li>Assert → Finally, the expectations are set, verifying certain side effects over the component markup. This form of unit testing is known as Arrange-Act-Assert.</li></ul><h4>Choosing the right tool</h4><p>When choosing testing tools, it is worth considering the following points: Speed vs. environment: Some tools offer a very quick feedback loop between making a change and seeing the result but do not model the browser behavior precisely. Other tools might use a real browser environment, but they reduce the iteration speed and are unreliable on a continuous integration server.</p><h4>What to mock</h4><p>With components, the difference between a “unit” and “integration” test can be indistinct. If you’re testing a form, should it also test the buttons of the form? Or should a button component have its own test suite? Should refactoring a button ever break the form test?</p><h3>React testing libraries/tools.</h3><p>There are various testing libraries for your React components. The react ecosystem with a Node.js background has Mocha, Chai, and Sinon to test JavaScript applications. Mocha is used as the test runner. Chai can be the assertion library. Sinon can be used optionally to test your JavaScript logic with objects such as spies, stubs, and mocks. These objects are pieces of code that can be used for different types of testing. All three testing libraries can be used to test React applications. However, another library called Enzyme is added to the mix to render your React components.</p><h3>Popular React testing libraries</h3><p>You can now test React components using Jest or React testing Library. Jest was released by Facebook to test React components and bring the combined power of Mocha, Chai, Sinon, and more. React Testing Library is a set of helpers that let you test React components without depending on their implementation details.</p><h3>Testing with Jest</h3><p>Jest is a JavaScript test runner and assertion library that offers spies, stubs, and mocks. Jest can be combined with Enzyme or React Testing Library to test your React components even more powerfully. It allows you to access the DOM via jsdom to test React components. Jest provides a great iteration speed combined with powerful features like mocking modules and timers, so you can have more control over how the code executes. Jest includes a command line tool for test execution. It also allows us to create mock functions with almost zero configuration and makes assertions easier to read. Furthermore, it offers “snapshot testing,” which helps us check and verify the component rendering result. Jest is installed as a dependency to React when using npx-create-react-app, along with the React Testing Library.</p><h3>Testing with React Testing Library</h3><p>React Testing Library provides light utility functions on top of react-dom and react-dom or test-utils in a way that encourages better testing practices. The utilities provided by this Library facilitate querying the DOM, finding form elements by their labels, and finding links and buttons from their text like a user would. It also exposes a recommended way to find elements where the text content and label are not understandable. This Library encourages your applications to be more accessible and allows you to test your components and how the end user uses them. This Library is a replacement for Enzyme.</p><h3>Benefits of React Test Library</h3><p>The primary purpose of React Testing Library is to increase confidence in your tests by testing your components in the same way an end user would use the components. Users are unaware of the backend of an application and are aware of only the output. This Library enables you to write your tests based on the component output. Rewriting your tests in the React Testing Library is worthwhile because you’ll be trading tests that slow you down for tests that give you more confidence and increase your productivity in the long run.</p><h3>Summary</h3><ul><li>Testing is a line-by-line review of how your code will execute.</li><li>You can render component trees in a simple test environment or a realistic browser environment.</li><li>Component tests flow through three phases: Arrange, Act, and Assert. React components can be tested using Mocha, Chai, Sinon, Jest, and React Testing Library.</li><li>Finally, React Testing Library increases confidence in your tests by testing your components like an end user would use the components.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c7595134e79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Your First React App in React 18 using Function Components, Class Components, Properties…]]></title>
            <link>https://medium.com/@rohanmathewalex/create-your-first-react-app-in-react-18-using-function-components-class-components-properties-f1de7f502230?source=rss-9d2a15870f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1de7f502230</guid>
            <category><![CDATA[functional-component]]></category>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[class-component]]></category>
            <dc:creator><![CDATA[Rohan Mathew alex]]></dc:creator>
            <pubDate>Wed, 08 May 2024 03:25:38 GMT</pubDate>
            <atom:updated>2024-05-08T03:26:33.341Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create Your First React App in React 18 using Function Components, Class Components, Properties, and States, and practice fetching and rendering data from APIs dynamically.</h3><ol><li>Run the following command to create a new React app named react-apps</li></ol><pre>npx create-react-app react-apps</pre><p>2. At the prompt, if it asks for a confirmation to proceed, press y and enter or return on the keyboard to confirm.</p><p>In a few seconds, the a directory named react-apps is created with all the necessary files and packages.</p><p>3. Change to the react-apps directory by running the following command.</p><pre>cd react-apps</pre><p>4. Click on App.js in the editor.</p><p>5. Replace the content of App.js with the following.</p><pre>function App() {<br>  return (<br>    &lt;div &gt;<br>      Hello World!<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>6. In the terminal window run the following commands one after the other.</p><pre>npm start</pre><p>7. <em>If you are running it on your local system, open the browser and type </em><em>http://localhost:3000 in the address bar.</em></p><p>The react-apps UI will appear on the browser. All the styling has been removed and you should see <strong>Hello World</strong> written on the page.</p><p>8. Now let’s start adding a component to the page. Edit App.js again and replace the content with the code given below.</p><pre>function App(props) {<br>  const colorStyle = {<br>    color:props.color,<br>    fontSize:props.size<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;div style={colorStyle}&gt;<br>      Hello World!<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>We have made changes to App.js to make it a component that will take some style settings as props. We now have to set the properties.</p><p><em>When the server is running, any changes made to the files are automatically picked up by the server.</em></p><p>9. To set the props of the App component, we will make changes in index.js. Click on the index.js in the editor.</p><p>10. Replace the content of index.js with the code given below. If you notice the root element is created in a different manner. This is how it is done from React 18 onwards.</p><pre>import React from &#39;react&#39;;<br>import App from &#39;./App&#39;;<br>import { createRoot } from &#39;react-dom/client&#39;;<br><br>// This is how it it is done from React 18 onwards<br>const container = document.getElementById(&#39;root&#39;);<br>const root = createRoot(container);<br>root.render(&lt;App color=&quot;green&quot; size=&quot;20px&quot;/&gt;);</pre><p>As can be seen in the code we are passing the color and size.</p><p>11. Now when you refresh the broswer rendering, it will be rerendered with the style.</p><p>12. Change the color and the size in index.js as per your preference, save and refresh the React application on the browser page to see the changes.</p><h3>Let’s set the props from outside and maintain the state of the component inside. The state we will maintain is the number of times the button is clicked.</h3><ol><li>Here you are going to add a state named counter, to keep track of the number of times the button is clicked. Replace the code in App.js with the following code and save it. Refresh the page that is rendered.</li></ol><pre>import React, {useState} from &#39;react&#39;;<br><br>const App = (props)=&gt; {<br>  const [counter, setCounter] = useState(0);<br><br>  let incrementCounter = ()=&gt; {<br>    setCounter(counter+1);<br>  }<br>  let colorStyle = {color:props[&#39;color&#39;],fontSize:props[&#39;size&#39;]}<br>    return (<br>      &lt;div style={colorStyle}&gt;<br>        React Component<br>        &lt;br /&gt;&lt;br /&gt;<br>        &lt;button onClick={incrementCounter}&gt;Click Me!&lt;/button&gt;<br>        &lt;br /&gt;&lt;br /&gt;<br>        {counter}<br>      &lt;/div&gt;<br>    );<br>  }<br><br>  export default App;</pre><p>You will see that the counter state is being refreshed everytime the button is clicked.</p><p>You will see that the counter state is being refreshed everytime the button is clicked.</p><p>Challenge: Add a reset button, when onCLick the state should reset to 0.</p><p>Solution:</p><pre><br>import React, {useState} from &#39;react&#39;;<br><br>const App = (props)=&gt; {<br>  const [counter, setCounter] = useState(0);<br><br>  let incrementCounter = ()=&gt; {<br>    setCounter(counter+1);<br>  }<br>  let resettCounter = ()=&gt; {<br>    setCounter(0);<br>  }<br>  let colorStyle = {color:props[&#39;color&#39;],fontSize:props[&#39;size&#39;]}<br>    return (<br>      &lt;div style={colorStyle}&gt;<br>        React Component<br>        &lt;br /&gt;&lt;br /&gt;<br>        &lt;button onClick={incrementCounter}&gt;Click Me!&lt;/button&gt;<br>        &lt;br /&gt;&lt;br /&gt;<br>        {counter}<br>        &lt;br /&gt;&lt;br /&gt;<br>        &lt;button onClick={resettCounter}&gt;ResSet Me&lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br><br>  export default App;<br><br><br><br><br>&lt;button onClick={resettCounter}&gt;Click Me!&lt;/button&gt;</pre><p>13. To stop the server, go to the main command window and press ctrl + c to stop the server.</p><h3>Exercise : Using states in functional components</h3><p>In this section we will see how to do the same exercise, the state being retrieved from an asynchronous method call.</p><ol><li>This script will require the axios module to run. Run the following command to install it.</li></ol><pre>npm install --save axios</pre><p>2. Replace the code in App.js with the following code. Here the fucntional component has been created using ES6 style.</p><pre>import axios from &#39;axios&#39;;<br>import React, {useState, useEffect} from &quot;react&quot;;<br><br>const App = (props)=&gt; {<br>    // Define the state for API data<br>    const [breeds, setBreeds] = useState([]);<br><br>    // Fetching data from API on component mount<br>    useEffect(() =&gt; {<br>        const url = &quot;https://dogapi.dog/api/v2/breeds&quot;;<br>        axios.get(url)<br>            .then(response =&gt; {<br>                // Set the fetched data to state<br>                setBreeds(response.data.data);<br>            })<br>            .catch(error =&gt; {<br>                console.error(&#39;Error fetching data:&#39;, error.message);<br>            });<br>    }, []);<br><br>    // Rendering the list of breeds<br>    return (<br>        &lt;div&gt;<br>            &lt;h2&gt;List of Dog Breeds&lt;/h2&gt;<br>            &lt;ul&gt;<br>                {breeds.map((breed, index) =&gt; (<br>                    &lt;li key={index}&gt;<br>                        &lt;h3&gt;{breed.attributes.name}&lt;/h3&gt;<br>                        &lt;p&gt;Life Span: {breed.attributes.life.min} - {breed.attributes.life.max} years&lt;/p&gt;<br>                        &lt;p&gt;Male Weight: {breed.attributes.male_weight.min} - {breed.attributes.male_weight.max} kg&lt;/p&gt;<br>                        &lt;p&gt;Female Weight: {breed.attributes.female_weight.min} - {breed.attributes.female_weight.max} kg&lt;/p&gt;<br>                        &lt;p&gt;Hypoallergenic: {breed.attributes.hypoallergenic ? &#39;Yes&#39; : &#39;No&#39;}&lt;/p&gt;<br>                    &lt;/li&gt;<br>                ))}<br>            &lt;/ul&gt;<br>        &lt;/div&gt;<br>    );<br>}<br><br>export default App;</pre><p>3. Run npm start in the terminal to start the react app</p><p>Now you will see all the data fetched from the URL</p><h3>Task</h3><p>Modify the code in App.js to use the same URL and to render the API details in the table format .</p><h4>Solution:</h4><pre>import axios from &#39;axios&#39;;<br>import React, {useState, useEffect} from &quot;react&quot;;<br><br>const App = (props) =&gt; {<br>    //Define the state for API data<br>    const [breeds, setBreeds] = useState([]);<br><br>    //Fetching data from API on component mount<br>    useEffect(() =&gt; {<br>        const url = &quot;https://dogapi.dog/api/v2/breeds&quot;;<br>        axios.get(url)<br>        .then(response =&gt; {<br>            console.log(response)<br>            //set the fetched data into state<br>            setBreeds(response.data.data);<br>        })<br>        .catch(error =&gt; {<br>            console.error(&#39;Error Fetching Data&#39;, error.message);<br>        });<br>        <br>    }, []);<br><br>    //Rendring the list of breeds<br>    return(<br>        &lt;div&gt;<br>        &lt;h2&gt;List of Dog Breeds&lt;/h2&gt;<br>        &lt;table&gt;<br>            &lt;thead&gt;<br>                &lt;tr&gt;<br>                    &lt;th&gt;Name&lt;/th&gt;<br>                    &lt;th&gt;Life Span&lt;/th&gt;<br>                    &lt;th&gt;Male Weight (kg)&lt;/th&gt;<br>                    &lt;th&gt;Female Weight (kg)&lt;/th&gt;<br>                    &lt;th&gt;Hypoallergenic&lt;/th&gt;<br>                &lt;/tr&gt;<br>            &lt;/thead&gt;<br>            &lt;tbody&gt;<br>                {breeds.map((breed, index) =&gt; (<br>                    &lt;tr key={index}&gt;<br>                        &lt;td&gt;{breed.attributes.name}&lt;/td&gt;<br>                        &lt;td&gt;{breed.attributes.life.min} - {breed.attributes.life.max} years&lt;/td&gt;<br>                        &lt;td&gt;{breed.attributes.male_weight.min} - {breed.attributes.male_weight.max}&lt;/td&gt;<br>                        &lt;td&gt;{breed.attributes.female_weight.min} - {breed.attributes.female_weight.max}&lt;/td&gt;<br>                        &lt;td&gt;{breed.attributes.hypoallergenic ? &#39;Yes&#39; : &#39;No&#39;}&lt;/td&gt;<br>                    &lt;/tr&gt;<br>                ))}<br>            &lt;/tbody&gt;<br>        &lt;/table&gt;<br>    &lt;/div&gt;<br>    )<br>}<br>export default App;</pre><h4>Congratulations!</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1de7f502230" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>