<?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 Aya Bellazreg on Medium]]></title>
        <description><![CDATA[Stories by Aya Bellazreg on Medium]]></description>
        <link>https://medium.com/@ayabellazreg?source=rss-cb34364da415------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*tKjN3Bke4_bgU6q41uLUZw.png</url>
            <title>Stories by Aya Bellazreg on Medium</title>
            <link>https://medium.com/@ayabellazreg?source=rss-cb34364da415------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 17:28:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayabellazreg/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[Fetch API For Beginners]]></title>
            <link>https://medium.com/@ayabellazreg/fetch-api-for-beginners-265561404598?source=rss-cb34364da415------2</link>
            <guid isPermaLink="false">https://medium.com/p/265561404598</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[fetch-api]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aya Bellazreg]]></dc:creator>
            <pubDate>Fri, 08 Mar 2019 19:16:19 GMT</pubDate>
            <atom:updated>2019-03-08T19:25:39.168Z</atom:updated>
            <content:encoded><![CDATA[<h4>Make your first application using the Fetch API</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J96_7Ee4-BHfNDQAq4o1tw.png" /></figure><p>In this tutorial, I will be explaining how to fetch data asynchronously from an external API using the Fetch API. I believe in learning by practice, so <a href="https://usingfetchapi.netlify.com/?_ga=2.50003750.1859332756.1550409495-484556510.1544356482"><strong>here</strong></a>’s the application we are going to build today!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*Fbi8IFmEOvSrrVOo1yYPYg.png" /><figcaption>The app we will be making today.</figcaption></figure><p><em>As usual, I will provide you with the </em><strong><em>Github repository</em></strong><em> at the end of this article.</em><br><strong>The app will cover:</strong></p><ul><li>Getting data from an external API (we will be using the <a href="https://jsonplaceholder.typicode.com/">placeholder API</a>).</li><li>Filtering the fetched data.</li><li>Submitting data to the API.</li></ul><p>First of all, we’ll need an <strong>interface </strong>to work with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec10649124c11185cf81d2a35983dc87/href">https://medium.com/media/ec10649124c11185cf81d2a35983dc87/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*f9-7YY7CmvJDJhJBZ6zTMA.png" /><figcaption>It will look something like this.</figcaption></figure><p>I am using<a href="https://getbootstrap.com/"><strong> </strong>bootstrap 4</a> here so we can avoid the custom styling.</p><p><strong><em>Note</em></strong><em>: In case you are wondering what </em><strong><em>babel</em></strong><em> is (included within the script tag); it is simply a JavaScript compiler. It will basically convert the code in ES6 to regular JS. That is for </em><strong><em>browser compatibility’s </em></strong><em>sake. You don’t have to include it unless you’re taking </em>browser compatibility <em>into consideration. You can read more about it </em><a href="https://babeljs.io/docs/en/"><em>here</em></a><em>.</em></p><ol><li><strong>Getting the data from the API</strong></li></ol><p>In order to get data from a server, we need to make an HTTP request.</p><p>The traditional way is to use AJAX, thus, our code would look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/676bfa6aa90b49f05e55800640e11d4b/href">https://medium.com/media/676bfa6aa90b49f05e55800640e11d4b/href</a></iframe><p>Admittedly, this way is kind of long and can become really tedious at times. That’s when the Fetch API comes into place; it is a really powerful web API to make <em>asynchronous requests </em>feasible<em>. </em>What I love about <strong>Fetch</strong> is that it returns a <a href="https://javascript.info/promise-basics"><strong><em>Promise</em></strong></a><strong><em>.</em></strong></p><blockquote>A promise is an object returned by a module, library, function, that will be resolved or rejected some time in the future.</blockquote><p>To get data using fetch , we’ll only need the endpoint URL which is the URL that we can use to access the data provided by the web API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a33cacdb1bee618f407fc54d3247e32/href">https://medium.com/media/5a33cacdb1bee618f407fc54d3247e32/href</a></iframe><p>Now let’s break it down step by step:</p><ul><li>We used fetch to send our request which returns a promise.</li><li>We called .then() to have access to the response that the API has provided, and then we returned it as <em>JSON</em>.</li><li>When the first promise gets <strong><em>resolved</em></strong>, we get the received data and display it to the DOM.</li></ul><p><a href="https://javascript.info/promise-chaining">More about promise chaining</a></p><p><strong><em>Note</em></strong><em>:</em> Don’t forget to add an <strong>EventListener </strong>to your button:</p><p>document.getElementById(&#39;postBtn&#39;).addEventListener(&#39;click&#39;,getPost);</p><p>You can add additional functionalities here such as searching for posts <strong>by title or id</strong> as in the example below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9422cd3d372761a75da3e80b7547023/href">https://medium.com/media/b9422cd3d372761a75da3e80b7547023/href</a></iframe><p>This is what we&#39;ve come across so far:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zePaqZ2kbkKAFHjoHuncQ.gif" /></figure><p>2. <strong>Submitting data to the API</strong></p><p>Now, what if you want to <em>send </em>data to the server?</p><p>With fetch , that’s pretty simple. It is the exact same process except this time, we’re going to add some <strong>options </strong>such as: the method, headers and the body.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*y0EPEqiMJ-XLE_oBsXYY4Q.png" /><figcaption>Example of options that you can add.</figcaption></figure><p>Now let’s create our submitPost() function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7187fc8ccbabc6308e7784f7e796be06/href">https://medium.com/media/7187fc8ccbabc6308e7784f7e796be06/href</a></iframe><p>It is that simple. Once you get a hold of the concept, the code will be much easier to play with.</p><p>If you enjoyed this tutorial, please click the 👏 button and share to help others find it! Feel free to leave a comment below if you have any questions.</p><p><a href="https://github.com/AyaBellazreg/Using-Fetch-API"><strong>Github repository</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=265561404598" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make a simple Shopping Cart App using React & Redux part 3]]></title>
            <link>https://medium.com/@ayabellazreg/make-a-simple-shopping-cart-app-using-react-redux-part-3-32b182e02cc9?source=rss-cb34364da415------2</link>
            <guid isPermaLink="false">https://medium.com/p/32b182e02cc9</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[shopping-cart-solutions]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aya Bellazreg]]></dc:creator>
            <pubDate>Sat, 22 Dec 2018 14:09:50 GMT</pubDate>
            <atom:updated>2018-12-22T14:09:50.440Z</atom:updated>
            <content:encoded><![CDATA[<h4>A simple guide to learn how to use React &amp; Redux to build a basic shopping cart app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*rZ1j7HMeLcZtfDCI-39hxA.jpeg" /></figure><p>In the last part we learned how to display items and add them to our Redux store. This time, let’s do the opposite; we’ll remove the added items from the DOM and the store in additon to adding(and subtracting) quantity via our Cart component.</p><p>In order to add or subtract the quantity, we firstly need to add onClick events the same way we did before with the addToCart function. So inside our Cart.js file, let’s add the following code(will be explained later):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20fd494e2ce8450fbe622d1415540b90/href">https://medium.com/media/20fd494e2ce8450fbe622d1415540b90/href</a></iframe><p>To explain this, we’ll just take one example(adding to quantity) since all the other examples are pretty much the same;</p><p>So once the target is clicked, we called the <strong>addQuantity </strong>function from the props. Here is where we need the <strong>mapDispatchToProps </strong>function; It basically dispatches the action to the reducer, and then we of course have to add that function as a parameter in the <strong><em>connect </em></strong>component.</p><p><strong>NOTE: Don’t forget to add all the mentioned actions into your cartActions file and then import them to the Cart.</strong></p><p>Now let’s add some changes inside our reducer to make this all work;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6a0fbf339f212ef58ac178ef858d81a/href">https://medium.com/media/c6a0fbf339f212ef58ac178ef858d81a/href</a></iframe><p>Here I used the<strong> if statement</strong>, but we generally use the <strong>switch statement.</strong></p><p>Now we’re going to display our total. For that, I’ve created another component called <strong>Recipe</strong>. So we want to import our total from the store and display it then add or remove this shipping, right? we’ve already done that a few times now, so you should be able to do it by your own now!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82e32fe43bd03b9751ab8d98557f42ae/href">https://medium.com/media/82e32fe43bd03b9751ab8d98557f42ae/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/650ed817b6cc64badb404c2d9e572757/href">https://medium.com/media/650ed817b6cc64badb404c2d9e572757/href</a></iframe><p>Now let’s handle our shipping actions:</p><ul><li>Add the shipping from the total:</li></ul><pre>if(action.type=== ADD_SHIPPING){</pre><pre>return{</pre><pre>...state,</pre><pre>total: state.total + 6</pre><pre>      }</pre><pre>}</pre><ul><li>Remove the shipping from the total:</li></ul><pre>if(action.type=== SUB_SHIPPING){</pre><pre>return{</pre><pre>...state,</pre><pre>total: state.total - 6</pre><pre>      }</pre><pre>}</pre><p>And now, the total should be updated depending on shipping option!</p><p>However, we should consider that when the user visits another page and comes back, the checkbox will remain unchecked but the value of total didn’t change. That will cause a problem; it will keep adding the shipping cost even when the checkbox remained unchecked because of the default action of the browser. So to solve that, we could simply add the <a href="https://reactjs.org/docs/react-component.html"><strong>componentWillUnmount()</strong></a><strong> </strong>function:</p><pre>componentWillUnmount() {</pre><pre>if(this.refs.shipping.checked)</pre><pre>this.props.substractShipping()</pre><pre>}</pre><p>We did target that checkbox using the name of our ref. We’ve already added a ref attribute to it, remember?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*uzyAU9Ah4p7-h2bsvNcL2g.png" /></figure><p>Full code of the Recipe component here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f39636fccba31765a4f648fba4c489e/href">https://medium.com/media/8f39636fccba31765a4f648fba4c489e/href</a></iframe><p><strong>Don’t forget to add it to your Cart component.</strong></p><p>That’s it! I hope I gave you a little insight about the React and Redux use and a better understanding about the concepts that comes in with Redux.</p><p><a href="https://github.com/AyaBellazreg/React-Shopping-Cart/tree/master/Shopping-Cart"><strong>Github repository</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32b182e02cc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make a simple Shopping Cart App using React & Redux part 2]]></title>
            <link>https://medium.com/@ayabellazreg/make-a-simple-shopping-cart-app-using-react-redux-part-2-88117cf1c069?source=rss-cb34364da415------2</link>
            <guid isPermaLink="false">https://medium.com/p/88117cf1c069</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[shopping-cart-solutions]]></category>
            <dc:creator><![CDATA[Aya Bellazreg]]></dc:creator>
            <pubDate>Wed, 19 Dec 2018 14:05:19 GMT</pubDate>
            <atom:updated>2018-12-22T14:13:40.267Z</atom:updated>
            <content:encoded><![CDATA[<h4>A simple guide to learn how to use React &amp; Redux to build a basic shopping cart app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NlqpTTAM8DbGl4paBmjE_g.jpeg" /></figure><p>In the last part we installed everything we need for the app. Furthermore; we created a navbar composed of a Home page and a Cart page but we haven’t created them yet.</p><ul><li><strong>The Home page</strong>: will display all the provided items and will allow us to add whatever quantity of items we need.</li><li><strong>The Cart page</strong>: will give us all the selected items with all the information about each product + the total.</li></ul><p>Firstly, let’s create the Home.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/581c6a1bb348a802639e7887ea6d1961/href">https://medium.com/media/581c6a1bb348a802639e7887ea6d1961/href</a></iframe><p>It will look something like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XBPQgN-NGndCBK2ElzGnDw.png" /></figure><p>However, we want to display our items, right? so we’re going to somehow <strong><em>connect </em></strong>the Home page with the data that we stored in the cartReducer.</p><p>To do that, we use the <strong><em>connect </em></strong>component from <strong><em>react-redux.</em></strong></p><pre>import { connect } from ‘react-redux’</pre><p>Then, we need to add the<strong> mapStateToProps </strong>function(more about it later).</p><pre>const mapStateToProps = (state)=&gt;{</pre><pre>return {</pre><pre>    items: state.items</pre><pre>     }</pre><pre>}</pre><p>Now we’ll <strong><em>connect </em></strong>this Home component to the data in our <strong><em>store </em></strong>and pass in our new function.</p><pre>export default connect(mapStateToProps)(Home)</pre><p><strong><em>The mapStateToProps function</em></strong><em>:Takes the state in our cartReducer and pass it as props in our file(in this case we only need the items).</em></p><p>Now that we have the items data in our props, we can manipulate it however we want;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ee9f8ce02867f705d1acc3e4948feaf/href">https://medium.com/media/7ee9f8ce02867f705d1acc3e4948feaf/href</a></iframe><p><strong>Finally, we get our displayed items:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3WW0defPcFoGgHNHf4WRJA.png" /></figure><p>The last step is to add items into the cart. For that; we need to add an <strong>onClick </strong>event to our add icon and affect it to a function that will lead eventually to add a new item to our store.</p><pre>onClick={()=&gt;{this.handleClick(item.id)}}</pre><p>Now let’s create that <strong>handleClick </strong>function:</p><pre>handleClick = (id)=&gt;{</pre><pre>this.props.addToCart(id);<br>}</pre><p>As you can see, we called an <strong>addToCart</strong> function(taking in the <strong><em>id of the targetted item </em></strong>as a parameter) from the props. This comes from creating a <strong>mapDispatchToProps </strong>function and connecting it to our reducer.</p><pre>const mapDispatchToProps= (dispatch)=&gt;{</pre><pre>return{</pre><pre>   addToCart: (id)=&gt;{dispatch(addToCart(id))}</pre><pre>     }</pre><pre>}</pre><p><strong>NOTE: addToCart is actually an action that the reducer will handle later on.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16c6bb99e3d6fc85151198af5319efb3/href">https://medium.com/media/16c6bb99e3d6fc85151198af5319efb3/href</a></iframe><p>Now let’s create that <strong>addToCart </strong>action inside our <strong>cartActions </strong>file:</p><pre>export const addToCart= (id)=&gt;{</pre><pre>return{</pre><pre>    type: ADD_TO_CART,</pre><pre>     id }</pre><pre>}</pre><p>And lastly, we’ll define how we’re going to handle our <em>addToCart </em>action once it’s dispatched to our reducer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70fefdb4684195c88fe0cc662f07c752/href">https://medium.com/media/70fefdb4684195c88fe0cc662f07c752/href</a></iframe><p>Now let’s display our added items in the Cart Component</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/802922c87e683cf6d9c88ed19988fb84/href">https://medium.com/media/802922c87e683cf6d9c88ed19988fb84/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F1dOLcCrqnRPsKULV73%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2F1dOLcCrqnRPsKULV73&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F1dOLcCrqnRPsKULV73%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="233" frameborder="0" scrolling="no"><a href="https://medium.com/media/41459381c798c0df934aef3df256990f/href">https://medium.com/media/41459381c798c0df934aef3df256990f/href</a></iframe><p>In the next part we’ll add the functionality of adding the quantity and removing an item or all the items.</p><p><a href="https://medium.com/@ayabellazreg/make-a-simple-shopping-cart-app-using-react-redux-part-3-32b182e02cc9"><strong>Next Part</strong></a></p><p><a href="https://github.com/AyaBellazreg/React-Shopping-Cart/tree/master/Shopping-Cart"><strong>Github repository</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88117cf1c069" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make a simple Shopping Cart App using React & Redux (1/3)]]></title>
            <link>https://medium.com/@ayabellazreg/make-a-simple-shopping-cart-app-using-react-redux-1-3-fefde93e80c7?source=rss-cb34364da415------2</link>
            <guid isPermaLink="false">https://medium.com/p/fefde93e80c7</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[shopping-cart]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Aya Bellazreg]]></dc:creator>
            <pubDate>Mon, 17 Dec 2018 13:18:26 GMT</pubDate>
            <atom:updated>2018-12-22T14:12:36.797Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make a simple Shopping Cart App using React &amp; Redux part 1</h3><h4>A simple guide to learn how to use React &amp; Redux to build a basic shopping cart app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NlqpTTAM8DbGl4paBmjE_g.jpeg" /></figure><p>Ok, so you may have heard of React and Redux since they’ve been all over the place lately. You may have found a bunch of tutorials and resources to learn the basics. However, when it comes to the real world you need to actually get started and build something using what you&#39;ve learnt.</p><p>Through this series, we’re going to learn how to implement Redux into a React project in order to build <em>a basic</em><strong><em> e-commerce website with a shopping cart.</em></strong></p><p><em>I will provide the </em><strong><em>Github repository</em></strong><em> for the full project at the end of this article.</em></p><p><strong>NOTE<em>: This article is meant for beginners who have just gotten started with React,so I’ll try to explain all the steps from scartch, bare with me!</em></strong></p><h3>Requirements</h3><ul><li>Node.js installed</li><li>A terminal (you can install Git Bash for Windows if you’re a Windows user)</li></ul><h3>Get started</h3><p>Inside you directory, execute the following command:</p><pre>npx create-react-app shopping-cart</pre><p>This will allow us to create the basic structure of a React app.</p><p>Now let’s get inside our new directory and run the project on a <em>localhost</em>:</p><pre>cd shopping-cart<br>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29DKWlT91ZUZRvr6ys7SLQ.png" /><figcaption>This is what we got so far wohoo! but hold on there’s more to come</figcaption></figure><p>We can now get rid of the files we don’t need(<strong>App.css, index.css</strong>).</p><p><em>Don’t forget to remove them from the</em><strong><em> index.js</em></strong><em> file.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_WMZRqoPCNWMce2GD6yQxg.png" /><figcaption>This is how your<strong> App.js</strong> file should look like.</figcaption></figure><h3>Now let’s get our hands dirty</h3><p>First of all, let’s create a new folder called components; this folder’s name is already self-explanatory, all of our components will be built there.</p><p>Let’s create our first file <strong>Navbar.js</strong> to create a simple <em>navbar:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d496f00e30522406ba6c2b4b12d2161/href">https://medium.com/media/8d496f00e30522406ba6c2b4b12d2161/href</a></iframe><p>We’re not going to focus on the styles in this article so I am using <a href="https://materializecss.com/getting-started.html">Materialize </a>to get awesome styles quickly. You can use something else or make your own styles. You’re free!</p><p><strong>NOTE<em>: The Link tag is just a simple component that we use instead of an anchor tag to prevent the default action of the browser (refreshing the page). But you first have to install the </em>react-router-dom.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZLQmNIxbXJOlrR0SIYtZ4w.png" /></figure><p>Then include the component into our App.js file.</p><p>Create the Home.js file which will display all our items. This is where we’re going to use Redux to manipulate data! So, in order to use <strong>Redux </strong>in the first place, we need to <strong>install </strong>it:</p><pre>npm install redux react-redux</pre><p>Ok, so we got ourselves all set to use Redux. Now all we need to do is to import the components that we need for this project. That is:</p><ul><li><strong><em>createStore: </em></strong><em>which allows us to create a store that holds all of our state </em>tree of our app(will be imported from ‘redux’).</li><li><strong><em>Provider</em></strong>: which will basically wrap our App component. It will simply allow us to pass our <strong>store </strong>into the props (will be imported from ‘react-redux’).</li></ul><p>So, let’s go ahead and create our store:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/504d6edacf46658bb1b3d786f66b284d/href">https://medium.com/media/504d6edacf46658bb1b3d786f66b284d/href</a></iframe><p>As you can see, our <strong><em>createStore </em></strong>component takes a <strong><em>reducer </em></strong>as a parameter. <br>In this case, we called it<strong> <em>cartReducer.</em></strong></p><blockquote>Reducers specify how the application’s state changes in response to <a href="https://redux.js.org/basics/actions">actions</a> sent to the store.</blockquote><p>Let’s simply take a reducer as a filter that filters the actions that have been sent. Depending on those actions, we’ll excute certain things.</p><p>Inside the components folder, create another folder called reducers within it a file called cartReducer.</p><p><strong>NOTE: Even though we have one reducer in this project, it’s common practice to create a reducers folder to keep your app organized and clean. In bigger projects this practice will save you from a lot of pain, same for <em>actions</em>(later).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*TL8ASXRRzEJ-A8P37T8arw.png" /></figure><p>Inside the cartReducer file, let’s create the cartReducer function. It takes in two parameters; the <strong><em>state </em></strong>and <strong><em>action.</em></strong></p><p>Our state will be just a bunch of data, or in other words, our <em>items.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab8f20efe1cc55160ed070e8f4be798b/href">https://medium.com/media/ab8f20efe1cc55160ed070e8f4be798b/href</a></iframe><p>In the next part we’ll create our first action which will lead us to display and add items to the cart.</p><p><a href="https://medium.com/@ayabellazreg/make-a-simple-shopping-cart-app-using-react-redux-part-2-88117cf1c069"><strong>Next Part</strong></a></p><p><a href="https://github.com/AyaBellazreg/React-Shopping-Cart/tree/master/Shopping-Cart"><strong>Github repository</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fefde93e80c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>