<?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 Asif Sharif on Medium]]></title>
        <description><![CDATA[Stories by Asif Sharif on Medium]]></description>
        <link>https://medium.com/@asiif.shariif?source=rss-8317f4cd7f58------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NdGS7ZPZntW_ZyQl7jidYA.jpeg</url>
            <title>Stories by Asif Sharif on Medium</title>
            <link>https://medium.com/@asiif.shariif?source=rss-8317f4cd7f58------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:18:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asiif.shariif/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[React Native CRUD list using Firebase Real time Database]]></title>
            <link>https://medium.com/@asiif.shariif/react-native-crud-list-using-firebase-real-time-database-483b95c0b1dd?source=rss-8317f4cd7f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/483b95c0b1dd</guid>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[lists]]></category>
            <dc:creator><![CDATA[Asif Sharif]]></dc:creator>
            <pubDate>Mon, 21 Jan 2019 09:25:59 GMT</pubDate>
            <atom:updated>2019-01-21T10:03:57.789Z</atom:updated>
            <content:encoded><![CDATA[<p>React Native CRUD list using Firebase Real time Database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QFrxRouYLDCTVR5b" /><figcaption>Photo by <a href="https://unsplash.com/@theexplorerdad?utm_source=medium&amp;utm_medium=referral">Joshua Ness</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Store and sync data with our NoSQL cloud database. Data is synced across all clients in realtime, and remains available when your app goes offline.</blockquote><p><a href="https://firebase.google.com/docs/database/">Firebase Realtime Database</a></p><p>I am using firebase real time database to perform CRUD on a simple list, the data is automatically sync across multiple devices and platform</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*Hqz06zWOgi3e6WkO2sh_Qg.gif" /></figure><p>Start using by cloning the repo, <a href="https://github.com/asifsha/rn-firebase">https://github.com/asifsha/rn-firebase</a></p><p>Please note you need to define firebase config in .firebase.config or in the App.js in below format.[ if defined in App.js do not export Config, just directly use it]</p><pre>var Config = {<br>    apiKey: &quot;&lt;API_KEY&gt;&quot;,<br>    authDomain: &quot;&lt;PROJECT_ID&gt;.firebaseapp.com&quot;,<br>    databaseURL: &quot;https://&lt;DATABASE_NAME&gt;.firebaseio.com&quot;,<br>    projectId: &quot;&lt;PROJECT_ID&gt;&quot;,<br>    storageBucket: &quot;&lt;BUCKET&gt;.appspot.com&quot;,<br>    messagingSenderId: &quot;&lt;SENDER_ID&gt;&quot;,<br>  };<br>export default Config;</pre><p>data format is below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*i69imN5lUxyiwIDT8apBpA.png" /></figure><p>cd rn-firebase</p><p>npm install</p><p>expo start</p><p>Below are code for add/ update/ delete / read operations.</p><p>Read data from firebase</p><pre>componentDidMount() {<br>    // start listening for firebase updates<br>    this.listenForTasks(this.tasksRef);<br>  }<br><br>  listenForTasks(tasksRef) {<br>    tasksRef.on(&quot;value&quot;, dataSnapshot =&gt; {<br>      var tasks = [];<br>      dataSnapshot.forEach(child =&gt; {<br>        tasks.push({<br>          name: child.val().name,<br>          key: child.key<br>        });<br>      });<br><br>      this.setState({<br>        dataSource: tasks<br>      });<br>    });<br>  }</pre><p>Add item</p><pre>var newPostKey = firebaseApp<br>      .database()<br>      .ref()<br>      .child(&quot;items&quot;)<br>      .push().key;<br><br>   <br>    var updates = {};<br>    updates[&quot;/items/&quot; + newPostKey] = {<br>      name:<br>        itemName === &quot;&quot; || itemName == undefined<br>          ? this.state.itemname<br>          : itemName<br>    };<br><br>    return firebaseApp<br>      .database()<br>      .ref()<br>      .update(updates);</pre><p>Update item</p><pre>var updates = {};<br>    updates[&quot;/items/&quot; + this.state.selecteditem.key] = {<br>      name: this.state.itemname<br>    };<br><br>    return firebaseApp<br>      .database()<br>      .ref()<br>      .update(updates);</pre><p>Delete item</p><pre>var updates = {};<br>    updates[&quot;/items/&quot; + key] = null;<br>    return firebaseApp<br>      .database()<br>      .ref()<br>      .update(updates);</pre><p>React Native Paper Dialog</p><pre>&lt;Portal&gt;<br>    &lt;Dialog<br>     visible={this.state.confirmVisible}<br>     onDismiss={() =&gt; this.hideDialog(false)}<br>    &gt;<br>    &lt;Dialog.Title&gt;Confirm&lt;/Dialog.Title&gt;<br>      &lt;Dialog.Content&gt;<br>        &lt;Paragraph&gt;Are you sure you want to delete this?&lt;/Paragraph&gt;<br>      &lt;/Dialog.Content&gt;<br>    &lt;Dialog.Actions&gt;<br>    &lt;Button onPress={() =&gt; this.hideDialog(true)}&gt;Yes&lt;/Button&gt;<br>    &lt;Button onPress={() =&gt; this.hideDialog(false)}&gt;No&lt;/Button&gt;<br>    &lt;/Dialog.Actions&gt;<br>    &lt;/Dialog&gt;<br> &lt;/Portal&gt;</pre><p>React Native Paper Snackbar</p><pre>&lt;Snackbar<br>  visible={this.state.snackbarVisible}<br>  onDismiss={() =&gt; this.setState({ snackbarVisible: false })}<br>  action={{<br>  label: &quot;Undo&quot;,<br>  onPress: () =&gt; {<br>  // Do something<br>  this.undoDeleteItem();<br>  }<br>  }}<br>  &gt;<br>  Item deleted successfully.<br>&lt;/Snackbar&gt;</pre><p>For other sample code see below link</p><p><a href="https://github.com/firebase/quickstart-js">https://github.com/firebase/quickstart-js</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=483b95c0b1dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native Picker Cascader]]></title>
            <link>https://medium.com/@asiif.shariif/react-native-picker-cascader-75feb640d8de?source=rss-8317f4cd7f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/75feb640d8de</guid>
            <category><![CDATA[dropdown]]></category>
            <category><![CDATA[cascader]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[select]]></category>
            <dc:creator><![CDATA[Asif Sharif]]></dc:creator>
            <pubDate>Thu, 10 Jan 2019 08:02:40 GMT</pubDate>
            <atom:updated>2019-01-10T08:14:15.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zzq9FKDB821Z3jdd" /><figcaption>Photo by <a href="https://unsplash.com/@marvelous?utm_source=medium&amp;utm_medium=referral">Marvin Meyer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So if you want to cascade multiple drop downs, it is always little bit difficult to sync them through their relationship, also on mobile UI, the space is limited so we have also limited space for multiple drop-downs.</p><p>For both above mentioned problems i designed picker cascader dropdown to solve both the issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*ZdjlG-haDpzU7yyhB8CRRg.gif" /></figure><p>Cascader also have search option.</p><p>You can pass data source as java script nested array, note that children object is always a array even if contain only one child.</p><pre>&lt;PickerCascader style={{ padding: 10 }} data={[<br>          {<br>            key: &#39;1&#39;, text: &#39;Australia&#39;, children: [{<br>              key: &#39;2&#39;, text: &#39;New South Wales&#39;,<br>              children: [{ key: &#39;3&#39;, text: &#39;Sydney&#39; }, { key: &#39;4&#39;, text: &#39;Wollongong&#39; }]<br>            },<br>            {<br>              key: &#39;5&#39;, text: &#39;Victoria&#39;,<br>              children: [{ key: &#39;6&#39;, text: &#39;Melbourne&#39; }, { key: &#39;7&#39;, text: &#39;Geelong&#39; }]<br>            }<br>            ]<br>          },<br>          {<br>            key: &#39;10&#39;, text: &#39;Canada&#39;,<br>            children: [<br>              {<br>                key: &#39;11&#39;, text: &#39;Alberta&#39;, children: [{ key: &#39;12&#39;, text: &#39;Calgary&#39; },<br>                { key: &#39;13&#39;, text: &#39;Brooks&#39; }]<br>              },<br>              {<br>                key: &#39;14&#39;, text: &#39;British Columbia&#39;, children: [{ key: &#39;15&#39;, text: &#39;Vancouver&#39; },<br>                { key: &#39;16&#39;, text: &#39;Vernon&#39; }]<br>              }<br><br>            ]<br>          },<br>          {<br>            key: &#39;20&#39;, text: &#39;United States&#39;,<br>            children: [<br>              {<br>                key: &#39;21&#39;, text: &#39;New York&#39;, children: [{ key: &#39;22&#39;, text: &#39;Albany&#39; },<br>                { key: &#39;23&#39;, text: &#39;Norwich&#39; }]<br>              },<br>              {<br>                key: &#39;24&#39;, text: &#39;Pennsylvania&#39;, children: [{ key: &#39;25&#39;, text: &#39;Farrell&#39; },<br>                { key: &#39;26&#39;, text: &#39;Parker&#39; }]<br>              }<br><br>            ]<br>          }<br>        ]}<br>          onValueChange={(item) =&gt; this.valueChanged(item)}&gt;<br>          &gt;<br>        &lt;/PickerCascader&gt;</pre><p>npm : <a href="https://www.npmjs.com/package/react-native-picker-cascader">https://www.npmjs.com/package/react-native-picker-cascader</a></p><p>github : <a href="https://github.com/asifsha/react-native-picker-cascader">https://github.com/asifsha/react-native-picker-cascader</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75feb640d8de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image resize in github pages]]></title>
            <link>https://medium.com/@asiif.shariif/image-resize-in-github-pages-42af4c80988c?source=rss-8317f4cd7f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/42af4c80988c</guid>
            <category><![CDATA[github-pages]]></category>
            <category><![CDATA[markdown]]></category>
            <category><![CDATA[resize]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[image]]></category>
            <dc:creator><![CDATA[Asif Sharif]]></dc:creator>
            <pubDate>Wed, 28 Nov 2018 07:57:03 GMT</pubDate>
            <atom:updated>2018-11-28T07:57:03.731Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MGBGKZu1OpjPCfr7" /><figcaption>Photo by <a href="https://unsplash.com/@dimitri_tyan?utm_source=medium&amp;utm_medium=referral">Dimitri Tyan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So I was creating my personal website on github pages, and got into the problem of resizing the image to show on github pages, I search and found some solutions but in the end below works for me.</p><pre>&lt;img width=”250&quot; height=”400&quot; src=”<a href="https://raw.githubusercontent.com/asifsha/react-native-api-integration/master/demo/demoartist.gif">https://raw.githubusercontent.com/asifsha/react-native-api-integration/master/demo/demoartist.gif</a>&quot; /&gt;</pre><p>Note the raw url for the img tag, see below live.</p><p><a href="https://asifsha.github.io/">About Me</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42af4c80988c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[react jet - React starter kit with Redux, Popup, Validation, Spinner, Reactstrap, Grid and form…]]></title>
            <link>https://medium.com/@asiif.shariif/react-jet-react-starter-kit-with-redux-popup-validation-spinner-reactstrap-grid-and-form-4864c0ffd88c?source=rss-8317f4cd7f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/4864c0ffd88c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Asif Sharif]]></dc:creator>
            <pubDate>Tue, 25 Sep 2018 15:24:12 GMT</pubDate>
            <atom:updated>2018-09-26T08:45:03.837Z</atom:updated>
            <content:encoded><![CDATA[<h3>react jet - React starter kit with Redux, Popup, Validation, Spinner, Reactstrap, Grid and form Controls</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yL481GX1e2GZvnkb" /><figcaption>“low angle photography of high-rise buildings with flying plane” by <a href="https://unsplash.com/@zyteng1997?utm_source=medium&amp;utm_medium=referral">Kelvin Zyteng</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>get a <strong>Jet </strong>start to your apps</h3><blockquote>you should have basic understanding for react and redux to understand this</blockquote><p>If you want to develop applications using react, you definitely need some help full libraries so that you can start quickly and does not fall into unnecessary things like creating your own data grid, numeric text box etc.</p><p>Most modern apps today require some common controls [Grid, date time picker], UI experience [showing spinner while processing] and you want this experience same throughout the app, to help with all these basic things,I developed a framework to gather all these things.</p><p>for the full code, <a href="https://github.com/asifsha/react-jet">https://github.com/asifsha/react-jet</a></p><p>Rest API in node JS for this framework, <a href="https://github.com/asifsha/react-jet-api">https://github.com/asifsha/react-jet-api</a></p><p>features for react-jet</p><ul><li><a href="https://github.com/axios/axios">axios</a> — API Helper</li><li><a href="https://github.com/Availity/react-block-ui">react-block-ui</a> — Showing Spinner for UI</li><li><a href="https://github.com/react-bootstrap-table/react-bootstrap-table2">react-bootstrap-table2</a> — Editable grid</li><li><a href="https://github.com/reactstrap/reactstrap">reactstrap</a> — Styling</li><li><a href="https://github.com/reduxjs/redux">redux</a> — State Store</li><li><a href="https://github.com/jquense/react-widgets">react-widgets</a> — DropDownList, DatePicker, NumericTextBox</li><li><a href="https://github.com/markusenglund/react-switch">react-switch</a> — Toggle button</li><li><a href="https://github.com/CodeSeven/toastr">toastr</a> — Notification to show any type of messages</li><li><a href="https://github.com/chriso/validator.js">validator</a> — Validate user input</li><li>Every control / component is used with a wrapper so you can replace it if you want at only one place.</li></ul><blockquote>if you want to learn more about react and redux, see <a href="https://medium.com/@asiif.shariif/react-redux-starter-kit-985b4970aca3">this</a></blockquote><p>code structure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*l7F2msJPClrsYYQKj_9ifA.png" /></figure><p>axios is used to send requests to server, if you want to use any other like fetch just replace in this file</p><pre>import axios from &#39;axios&#39;;<br><br>class ServiceApi {<br><br>    static getTypes() {<br><br>        return new Promise((resolve, reject) =&gt; {<br>            axios.get(&#39;/types&#39;)<br>                .then(function (response) {<br>                    if (response.data != null)<br>                    {<br>                        var arr=response.data.map(<br>                            x =&gt; { <br>                                var type = { id: x._id, name:x.name };<br>                                return type;<br>                         });                                  <br>                        resolve(arr);<br>                    }                        <br>                    else<br>                        resolve(response.data);<br>                })<br>                .catch(function (error) {<br>                    reject(error);<br>                })<br>                .then(function () {<br>                    // always executed<br>                });<br>            //resolve(([]));<br>        }<br>        );<br><br><br>    }   <br>}<br><br>export default ServiceApi;</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-jet/master/src/api/serviceApi.js">https://raw.githubusercontent.com/asifsha/react-jet/master/src/api/serviceApi.js</a></p><p>Spinner from <a href="https://www.npmjs.com/package/react-block-ui">react-block-ui</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ygrX6XZH75cR2AhFfTmgow.gif" /></figure><p>Grid from <a href="https://github.com/react-bootstrap-table/react-bootstrap-table2">react-bootstrap-table2,</a> it has a lot of use full features like Ingrid editing, sorting, multiple selection methods and so on.</p><p>If you want to replace this grid with some other grid control, you can do it in this file</p><p><a href="https://raw.githubusercontent.com/asifsha/react-jet/master/src/components/common/Grid.js">https://raw.githubusercontent.com/asifsha/react-jet/master/src/components/common/Grid.js</a></p><p>reactstrap — Easy to use React Bootstrap 4 components, used to style the app.</p><p>Popup from reactstrap <a href="https://reactstrap.github.io/components/modals/">modal</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0vzRda5ggJD11rBphia3NQ.gif" /></figure><p><a href="https://github.com/jquense/react-widgets">react-widgets</a> — DropDownList, DatePicker, NumericTextBox</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Up0lDFWu0Q-8vQ5kYz5JsA.gif" /></figure><p>Drop down is bind with remote data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*WFIe4SE6_vISDc2MpJ4LQQ.png" /><figcaption>assign props.itemTypes to data</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*aScTZrr4VE1mHMCKmvZniw.png" /><figcaption>call the action creator method</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*nb-zRITKasU4I9-5RDb5KA.png" /><figcaption>dispatch action</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*hx5I6zur6Alw2ng0uuIcCg.png" /><figcaption>actual service method to request data from server</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4HYmKU8red82wrE5ZUvaw.gif" /></figure><p><a href="https://github.com/markusenglund/react-switch">react-switch</a> — Toggle button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ALlvUwbTVaXW-nIfT3JMA.gif" /></figure><p><a href="https://github.com/CodeSeven/toastr">toastr</a> — Notification to show any type of messages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wl_EADcpiIlLQ0E7fUZTOg.gif" /></figure><p><a href="https://github.com/chriso/validator.js">validator</a> — Validate user input</p><pre>import validator from &#39;validator&#39;;<br><br><br>// all the validators should return ture on failure and false on success so that developer<br>// can skip !(not) operator for return value<br>class Validator {<br>    static validateRequired(value){        <br>        return validator.isEmpty(value + &#39;&#39;);<br>    }<br><br>    static validateInteger(value){             <br>        return !validator.isInt(value + &#39;&#39;);<br>    }<br><br>    static validateIntegerWithMin(value, min){             <br>        return !validator.isInt(value + &#39;&#39;, { min: min  });<br>    }<br><br>    static validateIntegerWithMax(value, max){             <br>        return !validator.isInt(value + &#39;&#39;, { max: max  });<br>    }<br><br>    static validateIntegerWithMinMax(value, min, max){          <br>        return !validator.isInt(value + &#39;&#39;, { min : min, max: max  });<br>    }<br>}<br><br>export default Validator;</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-jet/master/src/helper/validator.js">https://raw.githubusercontent.com/asifsha/react-jet/master/src/helper/validator.js</a></p><p>I developed some reusable components like <a href="https://github.com/asifsha/react-jet/tree/master/src">src</a>/<a href="https://github.com/asifsha/react-jet/tree/master/src/components">components</a>/<a href="https://github.com/asifsha/react-jet/tree/master/src/components/common">common</a>/DynamicButtonToolbar.js,<strong> </strong>for dynamically adding buttons</p><pre>import React from &#39;react&#39;;<br>import { ButtonGroup, Button } from &#39;reactstrap&#39;;<br><br><br>class DynamicButtonToolbar extends React.Component {<br><br>    render() {<br>       var buttonsItems = this.props.buttons.map(function (button) {<br>            return (<br>                &lt;Button key={button.id} id={button.id} color={button.style} onClick={button.handler}&gt;{button.text}&lt;/Button&gt;            );<br>        });<br>        return(<br>        &lt;ButtonGroup&gt;<br>            {buttonsItems}<br>        &lt;/ButtonGroup&gt;<br>        )<br>    }<br>}<br><br>export default DynamicButtonToolbar;<br></pre><p>And call it like this</p><pre>&lt;DynamicButtonToolbar buttons={[{<br>                    id: &#39;btnadd&#39;,<br>                    text: &#39;Add&#39;,<br>                    style: &#39;warning&#39;,<br>                    handler: this.onAdd<br>                },<br>                {<br>                    id: &#39;btnedit&#39;,<br>                    text: &#39;Edit&#39;,<br>                    style: &#39;info&#39;,<br>                    handler: this.onEdit<br>                },<br>                {<br>                    id: &#39;btnDelete&#39;,<br>                    text: &#39;Delete&#39;,<br>                    style: &#39;info&#39;,<br>                    handler: this.onDelete<br><br>                }]} /&gt;</pre><p>Every component has its own wrapper component/class so that it can be change from one place in code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*DwUALXa-xfr_RysXM2NJXA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4864c0ffd88c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Redux starter kit]]></title>
            <link>https://medium.com/@asiif.shariif/react-redux-starter-kit-985b4970aca3?source=rss-8317f4cd7f58------2</link>
            <guid isPermaLink="false">https://medium.com/p/985b4970aca3</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[store]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[get-started]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <dc:creator><![CDATA[Asif Sharif]]></dc:creator>
            <pubDate>Tue, 03 Jul 2018 13:54:29 GMT</pubDate>
            <atom:updated>2018-07-04T11:40:14.870Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KiKEuTRnxPSX9XQA" /><figcaption>Photo by <a href="https://unsplash.com/@anitaaustvika?utm_source=medium&amp;utm_medium=referral">Anita Austvika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To understand all the moving parts of React Redux, I developed a simple counter example, using react, redux, thung, actions generators, redux store. You can also use this architecture to build any front end app using react and redux, just remove all files and code related to counter use this structure.</p><p>I assume you know basic things like react, redux, store, thungs, this article is just about how to integrate all these things. You can find all the code at</p><p><a href="https://github.com/asifsha/react-redux-counter">https://github.com/asifsha/react-redux-counter</a></p><p>To begin create a new react app by typing npm create-react-app react-redux-counter</p><p>make sure you have the latest version of nodejs, react and create-react-app.</p><p>Create a new folder components in src and then create another folder app in it.</p><p>create index.js file in app folder</p><pre>import React from &#39;react&#39;;<br>import { Route } from &#39;react-router-dom&#39;<br>import CounterPage from &#39;../counter/index&#39;<br>import About from &#39;../about&#39;;<br>import Header from &#39;../common/Header&#39;;<br>import {withRouter} from &#39;react-router&#39;;<br>import { connect } from &#39;react-redux&#39;;<br><br>const App = () =&gt; (<br>  &lt;div&gt;<br>    &lt;header&gt;     <br>        &lt;Header/&gt;<br>    &lt;/header&gt;<br><br>    &lt;main&gt;<br>      &lt;Route exact path=&quot;/&quot; component={CounterPage} /&gt;<br>      &lt;Route exact path=&quot;/about-us&quot; component={About} /&gt;      <br>    &lt;/main&gt;<br>  &lt;/div&gt;<br>)<br><br>function mapStatesToProps(state, ownProps) {<br>  return {<br>      items: state.items<br>  };<br>}<br><br>const mapDispatchToProps = dispatch =&gt; ({<br> <br>}<br>)<br><br>export default withRouter(connect(mapStatesToProps, mapDispatchToProps)(App));</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/app/index.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/app/index.js</a></p><p>this will be the main component of our app.</p><p>add new folder common in src for shared/ common components, add Header.js in it</p><pre>import React from &#39;react&#39;;<br>import { Navbar,Nav,NavItem } from &#39;react-bootstrap&#39;;<br>import { Link } from &#39;react-router-dom&#39;<br><br><br>const Header = () =&gt; (<br>    &lt;Navbar&gt;       <br>        &lt;Nav&gt;         <br>            &lt;NavItem componentClass={Link} href=&#39;/&#39;   to=&#39;/&#39;&gt;Home&lt;/NavItem&gt;<br>            &lt;NavItem componentClass={Link} href=&#39;/about-us&#39; to=&#39;/about-us&#39;&gt;About&lt;/NavItem&gt;                       <br>        &lt;/Nav&gt;<br>    &lt;/Navbar&gt;<br>)<br>export default Header;</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/common/Header.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/common/Header.js</a></p><p>this will be our header component for the app.</p><p>create counter folder in components folder and add index.js and counterForm.js, it can be done in one file but its a good practice to separate out presentation and container components</p><pre>import React from &#39;react&#39;<br>import { bindActionCreators } from &#39;redux&#39;<br>import { connect } from &#39;react-redux&#39;<br>import * as counterActions from &#39;../../actions/counterActions&#39;;<br>import CounterForm from &#39;./counterForm&#39;;<br><br>export class CounterPage extends React.Component {<br>  <br> <br>  render() {   <br>      return (<br>          &lt;CounterForm<br>              count={this.props.count}              <br>              onIncrement={this.props.actions.increment}              <br>              onDecrement={this.props.actions.decrement}              <br>          /&gt;<br>      );<br>  }<br>}<br><br>const mapStateToProps = state =&gt; (   <br>    {        <br>  count: state.counter.count<br>  <br>})<br><br><br>const mapDispatchToProps = dispatch =&gt;   ({<br>    actions: bindActionCreators(counterActions, dispatch)<br>    }<br>)<br><br>export default connect(<br>    mapStateToProps,<br>    mapDispatchToProps<br>  )(CounterPage);</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/counter/index.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/counter/index.js</a></p><pre>import React from &#39;react&#39;;<br>import PropTypes from &#39;prop-types&#39;;<br>import { ButtonToolbar } from &#39;react-bootstrap&#39;;;<br><br>const CounterForm = ({ count, onIncrement, onDecrement, isIncrementing, isDecrementing }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Counter&lt;/h1&gt; <br>      &lt;h2&gt;Counter Value&lt;/h2&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;ButtonToolbar&gt;<br>        &lt;button         <br>          className=&quot;btn btn-primary&quot;<br>          bsStyle=&quot;primary&quot;<br>          onClick={onIncrement}&gt;Increment &lt;/button&gt;        <br><br>        &lt;button<br>          value={&#39;Decrement&#39;}          <br>          className=&quot;btn btn-success&quot;<br>          onClick={onDecrement}&gt;Decrement&lt;/button&gt;<br>       <br>      &lt;/ButtonToolbar&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>CounterForm.propTypes = {<br>  count: PropTypes.number.isRequired,<br>  onIncrement: PropTypes.func.isRequired, <br>  onDecrement: PropTypes.func.isRequired  <br>};<br><br>export default CounterForm;</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/counter/counterForm.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/counter/counterForm.js</a></p><p>create a folder about in component folder and add index.js file in it</p><pre>import React from &#39;react&#39;;<br><br>export default () =&gt; (<br>  &lt;div&gt;<br>    &lt;h1&gt;About Us&lt;/h1&gt;<br>    &lt;p&gt;This is the sample code to understand all the moving parts of React &amp; Redux including Action, Action creators,Redux Thunk, Reducers &lt;/p&gt;<br>  &lt;/div&gt;<br>)</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/about/index.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/components/about/index.js</a></p><p>replace contents for src/index.js</p><pre>import React from &#39;react&#39;<br>import { render } from &#39;react-dom&#39;<br>import { Provider } from &#39;react-redux&#39;<br>import { ConnectedRouter } from &#39;react-router-redux&#39;<br>import store, { history } from &#39;./store/store&#39;<br>import App from &#39;./components/app&#39;<br>import &#39;./index.css&#39;<br><br><br>const target = document.querySelector(&#39;#root&#39;)<br><br>render(<br>  &lt;Provider store={store}&gt;<br>    &lt;ConnectedRouter history={history}&gt;<br>      &lt;div&gt;<br>        &lt;App /&gt;<br>      &lt;/div&gt;<br>    &lt;/ConnectedRouter&gt;<br>  &lt;/Provider&gt;,<br>  target<br>)</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/index.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/index.js</a></p><p>now we are done with adding all the components now add actions.</p><p>create a new folder actions in src and create 2 files in it actionTypes.js, counterActions.js</p><pre>export const INCREMENT = &#39;counter/INCREMENT&#39;<br>export const DECREMENT = &#39;counter/DECREMENT&#39;</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/actions/actionTypes.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/actions/actionTypes.js</a></p><pre>import * as types from &#39;./actionTypes&#39;;<br><br><br>export const increment = () =&gt; {<br>    return dispatch =&gt; {    <br>  <br>      dispatch({<br>        type: types.INCREMENT<br>      })<br>    }<br>  }  <br>  <br>  export const decrement = () =&gt; {<br>    return dispatch =&gt; {    <br>  <br>      dispatch({<br>        type: types.DECREMENT<br>      })<br>    }<br>  }</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/actions/counterActions.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/actions/counterActions.js</a></p><p>now create a folder store in src and add store.js in it</p><pre>import { createStore, applyMiddleware, compose } from &#39;redux&#39;<br>import { routerMiddleware } from &#39;react-router-redux&#39;<br>import thunk from &#39;redux-thunk&#39;<br>import createHistory from &#39;history/createBrowserHistory&#39;<br>import rootReducer from &#39;.././reducers&#39;<br><br><br>export const history = createHistory()<br><br>const initialState = {}<br> <br>const enhancers = []<br>const middleware = [<br>  thunk,<br>  routerMiddleware(history)<br>]<br><br>if (process.env.NODE_ENV === &#39;development&#39;) {<br>  const devToolsExtension = window.devToolsExtension<br><br>  if (typeof devToolsExtension === &#39;function&#39;) {<br>    enhancers.push(devToolsExtension())<br>  }<br>}<br><br>const composedEnhancers = compose(<br>  applyMiddleware(...middleware),<br>  ...enhancers<br>)<br><br>const store = createStore(<br>  rootReducer,<br>  initialState,<br>  composedEnhancers  <br>)<br><br> export default store;</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/store/store.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/store/store.js</a></p><p>this is the basic file to configure Redux store</p><p>create a new folder reducers in src folder and add three files initialState.js,</p><pre>export default {<br>    counter: {<br>        count: 0<br>        <br>    }<br>};</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/reducers/initialState.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/reducers/initialState.js</a></p><p>I added initialstate for managing the initial state in a separate file</p><p>counterReducer.js</p><pre>import * as types from &#39;../actions/actionTypes&#39;;<br>import initialState from &#39;./initialState&#39;;<br><br><br>export default (state = initialState.counter, action) =&gt; {<br>  switch (action.type) {    <br><br>    case types.INCREMENT:<br>      return {<br>        ...state,<br>        count: state.count + 1<br>        <br>      };   <br><br>    case types.DECREMENT:<br>      return {<br>        ...state,<br>        count: state.count - 1<br>        <br>      };<br><br>    default:    <br>      return state;<br>  }<br>}</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/reducers/counterReducer.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/reducers/counterReducer.js</a></p><p>I am adding counter related reducers to its own file</p><p>index.js</p><pre>import {combineReducers} from &#39;redux&#39;;<br>import counter from &#39;./counterReducer&#39;;<br><br>const rootReducer= combineReducers({    <br>    counter    <br>});<br><br>export default rootReducer;</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/reducers/index.js">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/src/reducers/index.js</a></p><p>index.js is for combining all reducers for the app, write now we only have one reducer i.e counterReducer.</p><p>You may need to install dependencies like react, redux, react-dom, history, react-bootstrap, react-redux, react-router-dom, react-router-redux, redux-thunk,</p><p>or copy the package.json file and run npm install</p><pre>{<br>  &quot;name&quot;: &quot;react-redux-counter&quot;,<br>  &quot;version&quot;: &quot;0.1.0&quot;,<br>  &quot;private&quot;: true,<br>  &quot;dependencies&quot;: {<br>    &quot;react&quot;: &quot;^16.4.1&quot;,<br>    &quot;react-dom&quot;: &quot;^16.4.1&quot;,<br>    &quot;react-scripts&quot;: &quot;1.1.4&quot;,<br>    &quot;history&quot;: &quot;^4.7.2&quot;,<br>    &quot;react-bootstrap&quot;: &quot;^0.32.1&quot;,<br>    &quot;react-redux&quot;: &quot;^5.0.7&quot;,<br>    &quot;react-router-dom&quot;: &quot;^4.2.2&quot;,<br>    &quot;react-router-redux&quot;: &quot;^5.0.0-alpha.9&quot;,<br>    &quot;redux&quot;: &quot;^3.7.2&quot;,<br>    &quot;redux-thunk&quot;: &quot;^2.2.0&quot;<br>  },<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;react-scripts start&quot;,<br>    &quot;build&quot;: &quot;react-scripts build&quot;,<br>    &quot;test&quot;: &quot;react-scripts test --env=jsdom&quot;,<br>    &quot;eject&quot;: &quot;react-scripts eject&quot;<br>  }<br>}</pre><p><a href="https://raw.githubusercontent.com/asifsha/react-redux-counter/master/package.json">https://raw.githubusercontent.com/asifsha/react-redux-counter/master/package.json</a></p><p>I got help from these in developing this sample app.</p><ul><li><a href="https://app.pluralsight.com/library/courses/react-redux-react-router-es6/table-of-contents">Building Applications with React and Redux</a></li><li><a href="https://medium.com/@notrab/getting-started-with-create-react-app-redux-react-router-redux-thunk-d6a19259f71f">Getting started with create-react-app, Redux, React Router &amp; Redux Thunk</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=985b4970aca3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>