<?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 Abhishek Sharma on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Sharma on Medium]]></description>
        <link>https://medium.com/@absharma9796?source=rss-4f754022d2e0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tKVi_O--cL-HBdAT</url>
            <title>Stories by Abhishek Sharma on Medium</title>
            <link>https://medium.com/@absharma9796?source=rss-4f754022d2e0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:32:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@absharma9796/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[A special way to dispatch Redux Actions — React-Redux]]></title>
            <link>https://medium.com/swlh/a-special-way-to-dispatch-redux-actions-react-redux-3dded69ec1fa?source=rss-4f754022d2e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dded69ec1fa</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-redux]]></category>
            <category><![CDATA[functional-component]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Abhishek Sharma]]></dc:creator>
            <pubDate>Wed, 06 May 2020 09:59:28 GMT</pubDate>
            <atom:updated>2020-05-07T10:43:36.084Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*cnAeZGWFBFzYaESBi9saoA.jpeg" /><figcaption>React-Redux</figcaption></figure><h3>A special way to dispatch Redux Actions — React-Redux</h3><p>Hey folks! So most of you who use React must have stumbled upon or found a need to use Redux. Redux is a state management library that does an awesome job to maintain the state of and CONNECT your components like a charm.</p><blockquote><strong><em>1. This is a simple example of dispatching actions from React class component that most of us use at the early stages of development.</em></strong></blockquote><pre>import React,{ Component } from &#39;react&#39;;<br>import { connect } from &#39;react-redux&#39;;</pre><pre>const class SampleComponent extends Component {         <br>   this.props.dispatch(action());<br>}</pre><pre>export default connect()(SampleComponent);</pre><p>Here as you see you have to wrap your component around a connect function to enable your component to access the state that redux maintains as well as dispatch actions.</p><blockquote>2. <strong><em>The other cleaner way came with hooks which can be used in React functional components.</em></strong></blockquote><pre>import React from &#39;react&#39;;<br>import { useDispatch } from &#39;react-redux&#39;;</pre><pre>const SampleComponent = () =&gt; {<br>    const dispatch = useDispatch();<br>    dispatch(action());<br>}</pre><p>This is a very convenient way. No need of using the <em>connect() </em>wrapper anymore. But the only limitation of both the methods is that they can’t be used outside a React component else Redux will yell at you like anything.</p><p>And thus comes the final method,</p><blockquote>3. <strong><em>Dispatching actions directly using the redux store object</em></strong></blockquote><p>This is how a <em>redux store</em> boilerplate looks like</p><pre><em>// store.js</em><br>import { createStore } from &#39;redux&#39;;<br>import rootReducer from &quot;../reducers&quot;;</pre><pre><em>const</em> <strong>store </strong>= createStore(rootReducer)</pre><pre>export default <strong>store</strong>;</pre><p>This store has the actual dispatch method that redux provides. So if you want to dispatch actions outside React components you can simply do that by</p><pre>import <strong>store </strong>from &#39;<strong>store.js</strong>&#39;;</pre><pre>const notareactcomponent = () =&gt; {<br>    <strong>store.dispatch</strong>(action());<br>}</pre><p>The use cases might vary according to needs!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dded69ec1fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/a-special-way-to-dispatch-redux-actions-react-redux-3dded69ec1fa">A special way to dispatch Redux Actions — React-Redux</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>