<?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 ankur kushwaha on Medium]]></title>
        <description><![CDATA[Stories by ankur kushwaha on Medium]]></description>
        <link>https://medium.com/@ankur.kus1?source=rss-6f1c842be41------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Zb4hF1KzyEUXOowC.</url>
            <title>Stories by ankur kushwaha on Medium</title>
            <link>https://medium.com/@ankur.kus1?source=rss-6f1c842be41------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 19:52:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ankur.kus1/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[Micro-frontends: A new way to organize your React Components]]></title>
            <link>https://medium.com/@ankur.kus1/micro-frontends-a-new-way-to-organize-your-react-components-5bccbc4398b6?source=rss-6f1c842be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bccbc4398b6</guid>
            <dc:creator><![CDATA[ankur kushwaha]]></dc:creator>
            <pubDate>Sun, 26 Apr 2020 19:51:36 GMT</pubDate>
            <atom:updated>2020-04-27T04:44:14.464Z</atom:updated>
            <content:encoded><![CDATA[<h3>Micro-frontends: A new way to organize your frontend code</h3><blockquote>From martinfowler.com, <em>Microfrontend is “</em><strong><em>An architectural style where independently deliverable frontend applications are composed into a greater whole</em></strong><em>”</em></blockquote><p>Continuing the work explained in the article here at <a href="https://martinfowler.com/articles/micro-frontends.html">https://martinfowler.com/articles/micro-frontends.html</a> I decided to build something like that with custom-elements.</p><p>Idea is to build a Web component whom you can pass data and attach callback just like other HTML elements within React/Preact.</p><p>We will be using Preact for building web components.</p><h3>Create a Simple Web Component</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a859f094a39c1397b1ee8474fca8b37/href">https://medium.com/media/1a859f094a39c1397b1ee8474fca8b37/href</a></iframe><h4>Build the above custom-element to js library</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8de78ca263154f6da2c21a53f0c88424/href">https://medium.com/media/8de78ca263154f6da2c21a53f0c88424/href</a></iframe><h4>Run webpack to create a single library named ‘greeting.js’. just include the js file onto any page and it will work.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55a6d4ee0552352e5720d625f0d9e685/href">https://medium.com/media/55a6d4ee0552352e5720d625f0d9e685/href</a></iframe><h4>See the usage of &lt;greeting&gt; the file app.js</h4><pre>&lt;x-greeting name={JSON.stringify(this.state.name)} onion-change={this.onClick} &gt;&lt;/x-greeting&gt;</pre><p>We can only pass a string in custom elements, So in order to pass JSON object, we will have to JSON stringify it and use json.parse in the custom-element file.</p><p>We can pass callbacks for custom-events as well. Let&#39;s say our component is firing a custom event named ion-change , code for passing callback will be<br> <strong>PREACT</strong></p><pre>// Custom Element<br>// Add handler for &quot;ion-change&quot; event<br>&lt;greeting onion-change={() =&gt; console.log(&#39;IonChange&#39;)} /&gt;<br>// Add handler for &quot;IonChange&quot; event (note the casing)<br>&lt;greeting onIonChange={() =&gt; console.log(&#39;ionChange&#39;)} /&gt;</pre><p><a href="https://preactjs.com/guide/v10/web-components/">https://preactjs.com/guide/v10/web-components/</a></p><h4><strong>React/Any other JSX lib</strong></h4><pre><em>/** @jsx nativeEvents */</em></pre><pre><strong>import</strong> React, { useState } <strong>from</strong> &#39;react&#39;</pre><pre><strong>import</strong> nativeEvents <strong>from</strong> &#39;jsx-native-events&#39;</pre><pre><strong>export</strong> default function SomeComponent (props) {</pre><pre>const [ name, setName ] <strong>=</strong> useState(&#39;&#39;)</pre><pre><strong>return</strong> &lt;div&gt;</pre><pre>&lt;p&gt;My name is {name}&lt;/p&gt;</pre><pre>&lt;x-greeting <strong>onEventIonChange</strong>={ e =&gt; setName(e.detail) }&gt;&lt;/x-greeting&gt;</pre><pre>&lt;/div&gt;</pre><pre>}</pre><p>This JSX pragma allows users to declaratively attach event listeners to elements using the onEvent&lt;EventName&gt; syntax where &lt;EventName&gt; would be replaced by a <a href="https://en.wikipedia.org/wiki/Camel_case">camelCase</a> version of the event&#39;s name. So, a &#39;click&#39; event would use the prop onEventClick or a custom event with a name of accordion-toggle would use the onEventAccordionToggle prop.</p><p><a href="https://www.npmjs.com/package/jsx-native-events">https://www.npmjs.com/package/jsx-native-events</a></p><h4><strong>Native Implementation</strong></h4><pre>document.addEventListener(&#39;ion-change&#39;,function(e){<br>   console.log(e.detail)<br>})</pre><p>Above code will work with Chrome and other latest browsers. In order to make it work with IE, we have to add some polyfills</p><h4>Support for Custom-Elements and Custom events for IE</h4><pre>// index.html<br>&lt;script src=&quot;https://unpkg.com/@webcomponents/custom-elements&quot;&gt;&lt;/script&gt;</pre><pre>//Custom-elements require symbols, so include those polyfill as well<br>//app.js<br>import &quot;core-js/features/symbol&quot;;</pre><h4>greeting.js changes for IE</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3ee51a72f99016c123980534ecf0c81/href">https://medium.com/media/b3ee51a72f99016c123980534ecf0c81/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bccbc4398b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building plug and play web modules using preact]]></title>
            <link>https://medium.com/@ankur.kus1/building-plug-and-play-web-modules-using-preact-5a00fc1d9d8f?source=rss-6f1c842be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a00fc1d9d8f</guid>
            <category><![CDATA[preact]]></category>
            <category><![CDATA[web-module]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[ankur kushwaha]]></dc:creator>
            <pubDate>Sat, 21 Jul 2018 18:55:21 GMT</pubDate>
            <atom:updated>2018-07-21T19:09:59.138Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What are web modules?</strong></h3><p>A web module is a collection of HTML template, CSS and Javascript which can be easily pluggable to an existing websites. Here is my definition:</p><ul><li>It should be plug and play</li><li>All HTML, CSS and JS resource should be within the module</li><li>It should not affect the external styling and behavior</li><li>It should be same(style and behavior) across all environments</li><li>Uses events to interact with the parent environment</li><li>Uses arguments to pass data to web modules from parent environment</li></ul><h3>What is Preact</h3><p>Its a fast 3kB alternative to React with the same modern API. For more details: <a href="https://preactjs.com/">https://preactjs.com/</a></p><p>We all know what React is, its a javascript library used for building UI developed by Facebook. Its uses the Virtual DOM and enhanced diff algorithm to update UI with minimum cost.</p><h3>Why Preact instead of React</h3><p>Since we are just building modules that needs to get plugged to other websites so we don’t need a full fledged react library. Also its:</p><ul><li>Closer to React</li><li>faster 3k alternative to React’s ~45 .</li><li>Portable &amp; Embeddable</li><li>Is compatible to react plugins as well using preact-compat</li><li>Proptypes validation is stripped to make its size smaller</li></ul><h3>Now get to the coding part</h3><p>We will build a sample webpage with a Toggle module</p><ul><li>I created a toggle-switch component which is just a radio button with some styling to give a switch-type look</li><li>I created a Preact-component “ToggleSwitch” in toggleSwitch.js file which is decorated with @WebComponent.</li><li>I have used CSS-modules here so the classes will not interfare with parent page classes</li><li>The decorator @Webcomponent will take the “tag name” and Preact Component as input, then it will search for all tags on page with the specified tag name input. Then it will mount this given Preact Component inside each tag entry on that page.</li><li>This decorator will also pass the data-* attributes to module from the page to the Preact component as props.</li><li>There is one “observedAttributes” options to decorator, which when passed true, will keep an watch on attribute changes and re-render the Preact component with new attributes.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/320ebb7a40598dea229021ba8cf1adbb/href">https://medium.com/media/320ebb7a40598dea229021ba8cf1adbb/href</a></iframe><h3>Demo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*ECfnjTzvwXKOsoNP9FNOTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*RZhnZwmSVAB_kIYDdo8KEg.png" /></figure><h3>References</h3><blockquote><a href="https://github.com/ankur-kushwaha/Preact-web-module.git">https://github.com/ankur-kushwaha/Preact-web-module.git</a></blockquote><blockquote><a href="https://preactjs.com/">https://preactjs.com/</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a00fc1d9d8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to setup your Raspberry Pi for IoT]]></title>
            <link>https://medium.com/@ankur.kus1/how-to-setup-your-raspberry-pi-for-iot-e1d35147c88a?source=rss-6f1c842be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1d35147c88a</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[weaved]]></category>
            <category><![CDATA[vnc]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[ankur kushwaha]]></dc:creator>
            <pubDate>Sun, 02 Jul 2017 10:21:32 GMT</pubDate>
            <atom:updated>2017-07-02T10:32:09.210Z</atom:updated>
            <content:encoded><![CDATA[<p>In this guide, I will show you how you can setup your Raspberry Pi to create awsome projects for IoT.</p><ol><li>Buy a Raspberry pi from <a href="http://www.amazon.in/s/ref=bl_dp_s_web_976392031?ie=UTF8&amp;node=976392031&amp;field-brandtextbin=Raspberry+Pi">Amazon</a>.</li></ol><h3>Setup SD Card</h3><ol><li>Download a OS for your raspberry PI. You can download Rasbian from <a href="https://www.raspberrypi.org/downloads/raspbian/">here</a></li><li>You will need to use an image writing tool to install the image you have downloaded on your SD card.</li><li>Download <a href="https://etcher.io/">Etcher</a> and install it.</li><li>Connect an SD card reader with the SD card inside.</li><li>Open Etcher and select from your hard drive the Raspberry Pi .img or .zip file you wish to write to the SD card.</li><li>Select the SD card you wish to write your image to.</li><li>Review your selections and click ‘Flash!’ to begin writing data to the SD card.</li></ol><h3>Connect your PI via LAN</h3><ol><li>Open your SD card.</li><li>Create a empty file named ssh at root to enable SSH.</li><li>Find a file name ‘cmdline.txt’</li><li>Just append the below content after the rootwait</li></ol><pre>//just append after the space like <br>rootwait ip=192.168.1.2::192.168.1.1:255.255.255.0:rpi:eth0:off</pre><p>3. Now when you connect you PI, it will get the 192.168.1.2 as its IP address.</p><p>5. Connect to your PI using ssh pi@192.168.1.2 Default password is raspberry</p><p>4. If there is any problem connecting. Go to your Network and Sharing Center&gt;Ethernet&gt;Properties&gt;IPV4 Properties and set your IP address as 192.168.1.1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*g3gx5hqgqHa3opoRJSkjkg.png" /></figure><p>5. You will be able to connect to your PI using SSH.</p><h3>Setup WIFI in PI</h3><ul><li>Connect to your PI using SSH</li><li>Type `sudo iwlist wlan0 scan` to check your WIFI device is working properly and check your wifi is visible.</li><li>Type in console “sudo nano /etc/network/interfaces”. You will see something like this.</li></ul><pre># interfaces(5) file used by ifup(8) and ifdown(8)</pre><pre># Please note that this file is written to be used with dhcpcd<br># For static IP, consult /etc/dhcpcd.conf and &#39;man dhcpcd.conf&#39;</pre><pre># Include files from /etc/network/interfaces.d:<br>source-directory /etc/network/interfaces.d</pre><pre>auto lo<br>iface lo inet loopback</pre><pre>iface eth0 inet manual</pre><pre>allow-hotplug wlan0<br>iface wlan0 inet dhcp<br>    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf</pre><pre>allow-hotplug wlan1<br>iface wlan1 inet manual<br>    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf</pre><ul><li>Just make sure `iface wlan0 inet dhcp`. Instead of manual, it shoud be dhcp. This make sure you pi will get IP address from your router.</li><li>Now type sudo nano /etc/wpa_supplicant/wpa_supplicant.conf</li><li>Add your network information like this and save your changes using ctrl+x</li></ul><pre>country=GB<br>ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev<br>update_config=1</pre><pre>network={<br>    ssid=&quot;Kushwaha&quot;<br>    psk=&quot;kushwaha&quot;<br>}</pre><ul><li>At this point, wpa-supplicant will normally notice within a few seconds that a change has occurred, and it will try and connect to the network. If it does not, restart the interface with sudo wpa_cli reconfigure.</li><li>You will get connected to your wifi.</li><li>If you have modified your SD card cmdline.txt . Just remove the IP setting from that. Delete the below contents from your cmdline.txt</li></ul><pre>ip=192.168.1.2::192.168.1.1:255.255.255.0:rpi:eth0:off</pre><ul><li>Restart your PI and it will connect to your router</li><li>To get the IP address, check your router</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*-OSgJz-iYgAPzS1GlDOVXQ.png" /></figure><ul><li>Now you can connect to your PI using the IP address. Type ssh pi@&lt;ip address from router&gt; .</li></ul><h3>Access your PI from anywhere(using internet)</h3><p>This article assume that you are connected to internet via wifi router.</p><blockquote>if IP is static</blockquote><ol><li>In this case you just have to enable the port forwarding on your router.</li><li>Like here, I have forwarded the port 22 to the port 22 on IP address of my PI.</li><li>Check you public IP using <a href="http://www.whatsmyip.org/">www.whatsmyip.org</a></li><li>Lets say your static IP is 10.3.4.22 then you just have to do ssh pi@10.3.4.22</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*t4b66fPi-SsMccUyIJvMfA.png" /></figure><blockquote>if IP is dynamic</blockquote><ol><li>In this case, You cann’t rely on public IP get via <a href="http://www.whatsmyip.org/">www.whatsmyip.org</a> as this will change with time.</li><li>In this case, you can use <a href="https://developer.weaved.com/">Weaved Io</a>T</li><li>Create an account with Weaved Iot.</li><li>Then run the following command on your PI</li></ol><pre>sudo apt-get update<br>sudo apt-get install weavedconnectd<br>sudo weavedinstaller</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/0*X-9hAbFU0YcB2KN1." /></figure><p>Initially you won’t have any Weaved services installed, so the upper part is empty. Enter 1 to attach Weaved to an existing TCP service (host) on your Raspberry Pi. You should now see the following screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/0*sviceu4FWiWV0KZV." /></figure><p>Enter 1 for SSH.</p><p>Next, either accept the default port or enter a different port value if you changed the default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*hi8AWOoG3zKFXK9l." /></figure><p>Most of the time, you’ll just answer Y to choose the default port. If you have specifically changed the port for this service though, enter the alternate port you have used.</p><p>The installer confirms your choice and asks you to give this connection a name:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*330lMXz971u2DLot." /></figure><p>You will now return to the main menu, where you can see your Weaved Service Connection installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/0*gJbdZ18xe2qEEFMs." /></figure><p>From left to right, the columns show:</p><ul><li>The protocol name</li><li>The internal TCP port it is using</li><li>The name of the installed TCP host</li><li>The name you just gave this connection.</li></ul><p>If you happen to install a connection for which there is no installed service, you’ll see “WARNING-NONE” in the Service column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/0*DEFpA_5Ywlda1beU." /></figure><p>You can still install a Weaved Connection, but until you also install a corresponding service, nothing will happen when you try to connect.</p><p>Now login to your Weaved Account <a href="https://developer.weaved.com/portal/members/home.php">here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*7SE6QPWe1eE8MxghaltV-Q.png" /></figure><p>Just click on “pi”/name of your device. This will open a screen with the details to connect to your PI. This will work from anywhere using internet connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*wH8BcmzyTCmfmcbRK8Ha9w.png" /></figure><p>Reference: <a href="https://www.weaved.com/installing-weaved-raspberry-pi-raspbian-os/">https://www.weaved.com/installing-weaved-raspberry-pi-raspbian-os/</a></p><h3>Setup VNC Server on your PI</h3><blockquote>Sometimes it is not convenient to work directly on the Raspberry Pi. Maybe you would like to work on it from another device by remote control. In this case you need UI for your PI</blockquote><p>Here are the steps to setup a VNC server on your PI</p><h4>ENABLING VNC SERVER</h4><p>On your Raspberry Pi, run the following commands to make sure you have the latest version of VNC Connect:</p><pre>sudo apt-get update<br>sudo apt-get install realvnc-vnc-server realvnc-vnc-viewer</pre><p>You can enable VNC Server at the command line using <a href="https://www.raspberrypi.org/documentation/configuration/raspi-config.md">raspi-config</a>:</p><pre>sudo raspi-config</pre><p>Now, enable VNC Server by doing the following:</p><ul><li>Navigate to <strong>Interfacing Options</strong>.</li><li>Scroll down and select <strong>VNC &gt; Yes</strong>.</li></ul><p>By Default ,PI start without a GUI. VNC Server can create a <strong>virtual desktop</strong> for you, giving you graphical remote access on demand. This virtual desktop exists only in your Raspberry Pi’s memory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*qth5J_jIDxFYgfxH.png" /></figure><p>To create and connect to a virtual desktop:</p><ul><li>On your Raspberry Pi (using Terminal or via SSH), run vncserver. Make note of the IP address/display number that VNC Server will print to your Terminal (e.g. 192.167.5.149:1).</li><li>On the device you’ll use to take control, enter this information into <a href="https://www.realvnc.com/download/viewer/">VNC Viewer</a>.</li></ul><p>Reference:<a href="https://www.raspberrypi.org/documentation/remote-access/vnc/">https://www.raspberrypi.org/documentation/remote-access/vnc/</a></p><h3>Setup Nodejs and NPM in yo iur PI</h3><ol><li>node will come preinstalled in your PI</li><li>To update node, Just run the below command in terminal</li></ol><pre>sudo apt-get install nodejs npm<br>sudo npm install -g n<br>sudo n stable<br>sudo npm update -g npm</pre><h3>Setup NODE-Red for Flow based programming for IoT</h3><ol><li>Node-red comes preinstalled with Raspbian</li><li>To run the node-red, type node-red in your terminal</li><li>You can also start it by going to Start&gt;Programming&gt;Node-Red</li><li>By Default it will run on Port 1880</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FM0Mjo0J1X_Q%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DM0Mjo0J1X_Q&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FM0Mjo0J1X_Q%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a07521d4eb1345e44f85436a124544e1/href">https://medium.com/media/a07521d4eb1345e44f85436a124544e1/href</a></iframe><p>Reference:<a href="https://nodered.org/docs/hardware/raspberrypi">https://nodered.org/docs/hardware/raspberrypi</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1d35147c88a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[List of Useful libraries for your next React Web App]]></title>
            <link>https://codeburst.io/list-of-useful-libraries-for-your-next-react-web-app-1dc0e3d460b0?source=rss-6f1c842be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dc0e3d460b0</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[ankur kushwaha]]></dc:creator>
            <pubDate>Mon, 26 Jun 2017 06:33:20 GMT</pubDate>
            <atom:updated>2017-06-28T08:47:01.305Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>I have list down various libraries that you can use for your next react project.</blockquote><p>You can find all these libraries integrated in a sample React project <a href="https://github.com/ankur-kushwaha/React-starter">here</a></p><pre>git clone <a href="https://github.com/ankur-kushwaha/React-starter">https://github.com/ankur-kushwaha/React-starter</a></pre><h3>React</h3><blockquote>A declarative, component based and “learn-once write anyware” library for building User Interfaces</blockquote><ol><li><strong>react : </strong>React core library</li><li><strong>react-dom: </strong>This package serves as the entry point of the DOM-related rendering paths.</li><li><a href="https://github.com/nfl/react-helmet"><strong>react-helmet:</strong></a><strong> </strong>A document head manager for React.</li><li><a href="https://github.com/gaearon/react-hot-loader"><strong>react-hot-loader</strong></a><strong>: </strong>Tweak React components in real time. <a href="http://gaearon.github.io/react-hot-loader/">http://gaearon.github.io/react-hot-lo…</a></li><li><a href="http://redux.js.org/docs/basics/UsageWithReact.html"><strong>react-redux</strong></a><strong>: </strong>React binding for Redux</li><li><a href="https://github.com/ReactTraining/react-router"><strong>react-router:</strong></a><strong> </strong>Declarative routing for React <a href="https://reacttraining.com/react-router/">https://reacttraining.com/react-router/</a></li><li><a href="https://github.com/ReactTraining/react-router/tree/master/packages/react-router-dom"><strong>react-router-dom:</strong></a><strong> </strong>Dom binding for react-router</li><li><a href="https://www.npmjs.com/package/react-snapshot"><strong>react-snapshot</strong></a><strong>: </strong>A zero-configuration static pre-renderer for <strong>React</strong> apps</li><li><a href="https://github.com/reactjs/reselect"><strong>reselect</strong></a><strong>: </strong>Selector library for Redux</li><li><a href="http://storybook.js.org/"><strong>@storybook/react</strong></a> : Interactive development &amp; testing environment for React and React-Native UI components <a href="https://storybook.js.org/">https://storybook.js.org</a></li><li><a href="https://github.com/commissure/redbox-react"><strong>redbox-react</strong></a><strong>:</strong> A redbox (rsod) component to display your JavaScript errors.</li></ol><h3>Redux</h3><blockquote>Redux is a predictable state container for JavaScript apps.</blockquote><ol><li><a href="http://redux.js.org/docs/basics/UsageWithReact.html"><strong>react-redux</strong></a><strong>: </strong>React binding for Redux</li><li><a href="https://github.com/gaearon/redux-devtools"><strong>redux-devtools</strong></a><strong>: </strong>A live-editing time travel environment for <a href="https://github.com/reactjs/redux">Redux</a>.</li><li><a href="https://github.com/evgenyrodionov/redux-logger"><strong>redux-logger</strong></a><strong>: </strong>Logger for Redux</li><li><a href="https://github.com/redux-saga/redux-saga"><strong>redux-saga</strong></a><strong>: </strong>redux-saga is a library that aims to make side effects (i.e. asynchronous things like data fetching and impure things like accessing the browser cache) in React/Redux applications easier and better.</li><li><a href="https://github.com/leoasis/redux-immutable-state-invariant"><strong>redux-immutable-state-invariant</strong></a><strong>: </strong>Redux middleware that detects mutations between and outside redux dispatches. For development use only.</li><li><a href="https://github.com/calesce/redux-slider-monitor"><strong>redux-slider-monitor</strong></a><strong>: </strong>A custom monitor for Redux DevTools to replay recorded Redux actions</li><li><strong>redux-devtools-dock-monitor: </strong>A resizable and movable dock for <a href="https://github.com/gaearon/redux-devtools">Redux DevTools</a>.</li><li><a href="https://github.com/gaearon/redux-devtools-log-monitor"><strong>redux-devtools-log-monitor</strong></a><strong>: </strong>The default monitor for Redux DevTools with a tree view</li></ol><h3>BABEL</h3><blockquote><strong>Babel</strong> is a community-driven tool that helps you write code in the latest version of JavaScript.</blockquote><ul><li><strong>babel-core</strong>: Core module for babel</li><li><strong>babel-eslint</strong>: Parser for babel, ESLint using Babel as the parser. This will be required in your .eslintrc file</li><li><strong>babel-loader</strong>: Webpack loader for babel.</li><li><strong>babel-plugin-transform-react-constant-elements </strong>: Treat React JSX elements as value types and hoist them to the highest scope.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*hy-UoS_YD9WjpAnLullFfA.png" /></figure><ul><li><strong>babel-plugin-transform-react-remove-prop-types</strong>: Remove React propTypes from the production build, as they are only used in development. You can <strong>save bandwidth</strong> by removing them.</li><li><strong>babel-preset-es2015/babel-preset-react/babel-preset-stage-0</strong>: This is required for babel parser and will be required in .babelrc file</li></ul><h3>Webpack plugins and Loaders</h3><blockquote><em>webpack</em> is a <em>module bundler</em> for modern JavaScript applications</blockquote><ol><li><strong>compression-webpack-plugin</strong>: Webpack plugin for compressing your javascript files</li><li><strong>extract-text-webpack-plugin: </strong>Extract text from a bundle, or bundles, into a separate file. Mainly used to save css styles in external file for production build</li><li><a href="https://github.com/jantimon/html-webpack-plugin"><strong>html-webpack-plugin</strong></a><strong>: </strong>Simplifies creation of HTML files to serve your webpack bundles. Help to inject the js and css dependencies in your template</li><li><a href="https://github.com/JaKXz/stylelint-webpack-plugin"><strong>stylelint-webpack-plugin</strong></a><strong>: </strong>A webpack plugin to lint your CSS/Sass code using stylelint</li><li><strong>copy-webpack-plugin</strong>: Wepback plugin for simple copy from source folder to destination folder</li><li><strong>css-loader</strong>: Wepback loader to load your CSS files</li><li><a href="https://github.com/MoOx/eslint-loader"><strong>eslint-loader:</strong></a><strong> </strong>eslint loader for webpack</li><li><a href="https://github.com/webpack-contrib/file-loader"><strong>file-loader:</strong></a><strong> </strong>File loader for webpack.</li><li><a href="https://github.com/webpack-contrib/imports-loader"><strong>imports-loader</strong></a><strong>: </strong>The imports loader can add the necessary require(&#39;whatever&#39;) calls, so those modules work with webpack.</li><li><strong>sass-loader:</strong> SASS loader for webpack</li><li><a href="https://github.com/webpack-contrib/style-loader"><strong>style-loader</strong></a><strong>: </strong>Style loader for webpack. Adds CSS to the DOM by injecting a &lt;style&gt; tag</li><li><strong>url-loader: </strong>The url-loader works like the <a href="https://github.com/webpack-contrib/file-loader">file-loader</a>, but can return a DataURL if the file is smaller than a byte limit.Mainly used for loading fonts, images etc.</li><li><a href="https://github.com/webpack-contrib/exports-loader"><strong>exports-loader</strong></a><strong>: </strong>Exports variables from inside the file by appending `exports[…] = …` statements..</li><li><a href="https://github.com/postcss/postcss-loader"><strong>postcss-loader</strong></a><strong>: </strong>Postcss loader is used to do some css prcessing after loading the css like cssnext, autoprefixer etc.</li><li><a href="https://www.npmjs.com/package/resolve-url-loader"><strong>resolve-url-loader: </strong></a>Webpack loader that resolves relative paths in url() statements based on the original source file. Mainly used in font path in css.</li><li><a href="https://github.com/webpack/webpack-dev-middleware"><strong>webpack-dev-middleware: </strong></a>It’s a simple wrapper middleware for webpack. It serves the files emitted from webpack over a connect server. This should be used for development only.</li><li><a href="https://github.com/glenjamin/webpack-hot-middleware"><strong>webpack-hot-middleware</strong></a><strong>: </strong>Webpack hot reloading using only <a href="http://webpack.github.io/docs/webpack-dev-middleware.html">webpack-dev-middleware</a>. This allows you to add hot reloading into an existing server without <a href="http://webpack.github.io/docs/webpack-dev-server.html">webpack-dev-server</a>.</li></ol><h3>Testing</h3><ol><li><a href="https://github.com/facebook/jest"><strong>jest</strong></a><strong>: </strong>Delightful JavaScript Testing with easy setup,instant feedback and snapshot testing.</li><li><a href="https://www.npmjs.com/package/enzyme"><strong>enzyme: </strong></a>Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components’ output.</li><li><a href="https://www.npmjs.com/package/react-test-renderer"><strong>react-test-renderer</strong></a><strong>: </strong>Used with jest to render the react component</li></ol><h3>Linting</h3><ol><li><a href="http://eslint.org/"><strong>eslint</strong></a><strong>: </strong>A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.</li><li><a href="https://www.npmjs.com/package/eslint-plugin-react"><strong>eslint-plugin-react</strong></a><strong>: </strong>React specific linting rules for ESLint</li><li><a href="https://github.com/MoOx/eslint-loader"><strong>eslint-loader:</strong></a><strong> </strong>eslint loader for webpack</li><li><strong>babel-eslint</strong>: Parser for babel, ESLint using Babel as the parser. This will be required in your .eslintrc file</li></ol><h3>Other Useful Libraries</h3><ol><li><a href="https://github.com/mzabriskie/axios"><strong>axios</strong></a><strong>: </strong>Promise based HTTP client for the browser and node.js</li><li><strong>config</strong>: Library to manage configuration for various enviroments</li><li><strong>cross-env</strong>: Run scripts that set and use environment variables across platforms</li><li><strong>express: </strong>Nodejs server framework for serving your files during development</li><li><strong>http-server: </strong>A simple http server to serve your files.Mainly used for testing your production build</li><li><strong>jquery: </strong>Dom manipulation library</li><li><strong>node-sass: </strong>A nodejs utility to compile your scss files to css.</li><li><a href="https://github.com/typicode/husky"><strong>husky</strong></a><strong>: </strong>Git hooks made easy. Husky can prevent bad commit, push. Basically you can set precommit, prepush hooks</li><li><a href="https://github.com/isaacs/rimraf"><strong>rimraf</strong></a><strong>: </strong>A `rm -rf` util for nodejs. For cleaning build directory before new build</li><li><strong>bootstrap: </strong>A responsive css framework</li><li><a href="https://github.com/matthew-andrews/isomorphic-fetch"><strong>isomorphic-fetch</strong></a><strong>: </strong>Isomorphic WHATWG Fetch API, for Node &amp; Browserify</li><li><a href="https://lodash.com/"><strong>lodash</strong></a><strong>:</strong>A JavaScript utility library delivering consistency, modularity, performance, &amp; extras.</li><li><strong>raven-js : </strong>JavaScript client for Sentry. Sentry’s real-time error tracking gives you insight into production deployments and information to reproduce and fix crashes.</li><li><a href="http://cssnext.io/"><strong>cssnext</strong></a>: Use tomorrow’s CSS syntax, today.</li><li><a href="http://cssnano.co/"><strong>cssnano</strong></a>: cssnano takes your nicely formatted CSS and runs it through many focused optimisations, to ensure that the final result is as small as possible for a production environment.</li><li><strong>autoprefixer</strong>: Parse CSS and add vendor prefixes to rules by Can I Use <a href="https://twitter.com/autoprefixer">https://twitter.com/autoprefixer</a></li></ol><p>I will keep on updating this list. Do let me know in comments if I miss something.</p><h3>References</h3><p><a href="https://github.com/nicksp/redux-webpack-es6-boilerplate">https://github.com/nicksp/redux-webpack-es6-boilerplate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dc0e3d460b0" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/list-of-useful-libraries-for-your-next-react-web-app-1dc0e3d460b0">List of Useful libraries for your next React Web App</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build your own React Component library with lerna and storybook]]></title>
            <link>https://codeburst.io/build-your-own-react-component-library-with-lerna-and-storybook-53298b186760?source=rss-6f1c842be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/53298b186760</guid>
            <category><![CDATA[sinopia]]></category>
            <category><![CDATA[storybook]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[pm2]]></category>
            <category><![CDATA[lerna]]></category>
            <dc:creator><![CDATA[ankur kushwaha]]></dc:creator>
            <pubDate>Wed, 21 Jun 2017 17:35:27 GMT</pubDate>
            <atom:updated>2017-06-22T01:59:03.140Z</atom:updated>
            <content:encoded><![CDATA[<p>We will be building our own component library in React. We will then publish them on NPM so that they will be available for all.</p><p>Here are the few libraries we are going to use.</p><ol><li>Lerna : for publishing npm modules</li><li>Storybook and its addons for independent component development</li><li>jest for testing</li></ol><h3>Setup Project</h3><pre>git clone <a href="https://github.com/ankur-kushwaha/react-component-library.git">https://github.com/ankur-kushwaha/react-component-library.git</a><br>cd react-component-library<br>yarn<br>//after the installation complete<br>yarn storybook</pre><ol><li>This will start a server at port 9001. Here is the user interface.</li><li>I have added a component called Button which takes single prop to update the background color of button. Similarity you can add multiple components and properties.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hQLlUhnQLtqddCraKHQfQ.png" /></figure><p>3. You can also test you component by changing the input arguments in the right side box. Type green and see changes.</p><h3>Folder Structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*asSsXknHqyuwOopB1qr_Nw.png" /></figure><ol><li>The packages folder will contains all the components.</li><li>All components should be complete on their own. Like they must have a package.json to maintain their version.</li><li>Package.json file should have a main property set to point the entry point.</li><li>Its always better to compile the es6 source-code to es5 using babel.</li><li>All these optimization is done in Button component.</li></ol><h3>Storybook Enhancement using Addons</h3><ol><li><strong>addon-knobs: </strong>Storybook Addon Knobs allow you to edit React props dynamically using the Storybook UI. You can also use Knobs as a dynamic variable inside stories in <a href="https://storybook.js.org/">Storybook</a>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C5ycv729CK-EDzc1.png" /></figure><p>2. <strong>addon-storyshots: </strong>StoryShots adds automatic Jest Snapshot Testing for <a href="https://storybook.js.org/">Storybook</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KMc-zT5m5ixEMzWi.png" /></figure><p>3. <strong>addon-info : </strong>Storybook Info Addon will show additional information for your stories in <a href="https://storybook.js.org/">Storybook</a>. Useful when you want to display usage or other types of documentation alongside your story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0BSIkmtNepKbPQqL.png" /></figure><p>4. <strong>addon-options: </strong>The Options addon can be used to set configure the <a href="https://storybook.js.org/">Storybook</a> UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hBieqOPT5KC997jK.png" /></figure><h3>Publishing Components</h3><p>So we have completed the steps for creating the independent components. Now its time to publish them. Here we are going to use lerna . Lerna can identify the components which have changed and suggest you to update the version in their package.json before publish them.</p><p>You can maintain different version for each component.</p><p>Before publish, run the below command to login to npm</p><pre>npm login</pre><p>You must create account on npm first, and your npm credentials here</p><pre>//first commit your changes in git repo<br>git remote add origin &lt;your git repo&gt;<br>git commit -am &quot;done&quot;<br>git push</pre><pre>//setup lerna for new components<br>lerna bootstrap<br>lerna publish</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*LtN-tT4tLaqAVRf2P0anxA.png" /></figure><p>It will check which component has changed,then</p><ol><li>specify the version.</li><li>Type y and hit enter</li><li>Packages published to npm registry.</li></ol><p><strong>In case:</strong></p><ol><li>You are getting error as you are not authorized to publish . This means that the package name is already taken.</li><li>If you are using @something/button This means that the package is scoped. This requires an access to private registry account on npm.</li><li>If you want to setup your own private NPM registery. You can setup sinopia on your machine</li></ol><pre>npm install -g sinopia<br>// then run the sinopia and it will start the npm private server<br>sinopia</pre><pre>// if you want to handle sinopia crashes automatically. You can use // pm2 to manage that<br>npm install -g pm2<br>pm2 pm2 start &quot;C:\Users\&lt;user&gt;\AppData\Roaming\npm\node_modules\sinopia\bin\sinopia&quot;</pre><h3>References</h3><p>Lerna: <a href="https://lernajs.io/">https://lernajs.io/</a><br>Storybook: <a href="https://storybook.js.org/">https://storybook.js.org/</a><br>PM2: <a href="https://github.com/Unitech/pm2">https://github.com/Unitech/pm2</a><br>Sinopia: <a href="https://github.com/rlidwka/sinopia">https://github.com/rlidwka/sinopia</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53298b186760" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/build-your-own-react-component-library-with-lerna-and-storybook-53298b186760">Build your own React Component library with lerna and storybook</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build REST API using Flow Based Programming (Node-Red)]]></title>
            <link>https://medium.com/@ankur.kus1/build-rest-api-using-flow-based-programming-node-red-4ed343228ba?source=rss-6f1c842be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ed343228ba</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node-red]]></category>
            <dc:creator><![CDATA[ankur kushwaha]]></dc:creator>
            <pubDate>Tue, 13 Jun 2017 16:43:31 GMT</pubDate>
            <atom:updated>2017-06-13T16:43:56.034Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What is Flow Based Programming</strong></h3><blockquote>In <a href="https://en.wikipedia.org/wiki/Computer_programming">computer programming</a>, <strong>flow-based programming</strong> (<strong>FBP</strong>) is a <a href="https://en.wikipedia.org/wiki/Programming_paradigm">programming paradigm</a> that defines <a href="https://en.wikipedia.org/wiki/Application_software">applications</a> as networks of “black box” <a href="https://en.wikipedia.org/wiki/Process_(computer_science)">processes</a>, which exchange data across predefined connections by <a href="https://en.wikipedia.org/wiki/Message_passing">message passing</a>, where the connections are specified <em>externally</em> to the processes. These black box processes can be reconnected endlessly to form different applications without having to be changed internally. FBP is thus naturally <a href="https://en.wikipedia.org/wiki/Software_componentry">component-oriented</a>.</blockquote><h3><strong>What is Node Red</strong></h3><blockquote>Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.</blockquote><blockquote>It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.</blockquote><p>However node-red is basically built for writing flow for IoT. However you can use it for building your REST api well. Here I will show you how you can setup node-red to create REST api.</p><p>Node-red is currently pre-installed with Raspbian for Raspberry-pi.</p><h3><strong>Setup Node-red</strong></h3><ol><li>Its a nodeJs library, hence make sure you have updated version of nodejs and npm.</li><li>Open terminal/cmd. Install node-red globally using the below command</li></ol><p>sudo npm install -g --unsafe-perm node-red</p><p>3. Now type node-red and it will start the server.</p><p>4. Open browser and type http://localhost:1880 .This will open the Node-red web interface like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j21AvKRox0NTPFtzt7X-yQ.png" /></figure><p>5. On the left pane you will see various node that can be dragged to the workspace to be a part of our flow.</p><p>6. Here is a video to demonstrate how you can use node-red to pull tweets from twitter.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Ff5o4tIz2Zzc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Df5o4tIz2Zzc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Ff5o4tIz2Zzc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f9e28a71a5bf5fab63ab7853558b283/href">https://medium.com/media/1f9e28a71a5bf5fab63ab7853558b283/href</a></iframe><h3><strong>How to create REST API</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJP2nkuuhS8wSH3bKRUI9g.png" /></figure><ol><li>Use the http node from the input block to handle request from outside. Here I have created a /users node.</li><li>Drag the http response node from the output block. This will output the payload of the msg as response of API.</li><li>Now go to your browser and hit <a href="http://localhost:1880/users.">http://localhost:1880/users</a> . You will see the below response.</li><li>Here is an another example</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*yq7vxE_nmPPLySVTvwRn4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*rGpwMheVsm_N9wQS37P59A.png" /></figure><p>5. Here I have used a mongodb node to connect to my local mongo database and fetch the data in twitter collecation.</p><h3><strong>References</strong>:</h3><ol><li><a href="http://nodered.org/">http://nodered.org/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ed343228ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using React-Native just for UI development in Android App]]></title>
            <link>https://medium.com/@ankur.kus1/building-an-android-app-using-react-native-e315bbba3814?source=rss-6f1c842be41------2</link>
            <guid isPermaLink="false">https://medium.com/p/e315bbba3814</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[ankur kushwaha]]></dc:creator>
            <pubDate>Sun, 28 May 2017 09:35:26 GMT</pubDate>
            <atom:updated>2017-05-28T09:38:31.365Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ow-J0bVpiyc1E-CofIY9Rg.png" /><figcaption>React Native</figcaption></figure><p>This article describe how you can create your first android application using React Native</p><p>Here are steps by steps instruction to do that.</p><p><strong>Setup the Android Environment</strong></p><ul><li>Download Android studio from <a href="https://developer.android.com/studio/index.html">https://developer.android.com/studio/index.html</a></li><li>Create an simple android project.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wfZup0Apht0_hc4pJrUZoA.png" /></figure><ul><li>Setup Android Emulator(AVD) to run you application</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5eZf0GujJs9at9_1rvtbVA.png" /></figure><p>3. Create a new Virtual Device</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8tNI0Uko_l5CPe69F6biOA.png" /></figure><ul><li>Now run your application, it would open up in the Android Emulator.</li><li>Now if you want to do coding in java, you can start using as it is. Android Studio provides all the features to build UI using xml. But if you are a web developer and more comfortable in Javascript and react, you can move to React-Native <a href="https://facebook.github.io/react-native/docs/getting-started.html">https://facebook.github.io/react-native/docs/getting-started.html</a>.</li></ul><p><strong>Setup the React Native</strong></p><ul><li>Install react native cli</li></ul><blockquote>npm install -g react-native-cli</blockquote><ul><li>Create a react-native project</li></ul><blockquote>react-native init project-name</blockquote><ul><li>Start your emulator. you can start emulator using android studio or run the below command</li></ul><blockquote>~/Library/Android/sdk/tools/emulator <a href="http://twitter.com/Nexus_5X_API_25">@Nexus_5X_API_25</a></blockquote><p><a href="http://twitter.com/Nexus_5X_API_25">Nexus_5X_API_25</a>: Name of my emulator</p><ul><li>Run your react native application</li></ul><blockquote>react-native run-android</blockquote><ul><li>If you want to develop you application completely in javascript, thats all it is, But there are chances when there is some functionality you require is not in react-native modules. In that case you can build your own java modules. In order to do that you have to merge both these application: React native project and Android studio project.</li><li>We will discuss how we can communication between them.</li></ul><p><strong>Merge React Native and Android environment</strong></p><ul><li>Go to the react project directory</li><li>Delete the android folder</li><li>Now copy the project folder from the Android Studio project and move it to the react-native project directory with the folder name as “android”</li><li>Delete the “activity_main.xml” from the folder “android/app/src/main/res/layout”</li><li>Create a file “MyReactActivity”android/app/src/main/java/&lt;package&gt;/ and add the below content</li></ul><pre><strong>import </strong>com.facebook.react.ReactActivity;<br><br><strong>public class </strong>MyReactActivity <strong>extends </strong>ReactActivity {<br><br>    <em>/**<br>     * Returns the name of the main component registered from JavaScript.<br>     * This is used to schedule rendering of the component.<br>     */<br>    </em>@Override<br>    <strong>protected </strong>String getMainComponentName() {<br>        <strong>return &quot;firstReact&quot;</strong>; <br>//this should be same as you have specified in &quot;index.android.js&quot; under AppRegistry.registerComponent</pre><pre>}<br>}</pre><ul><li>Create a file “MainApplication” android/app/src/main/java/&lt;package&gt;/ and add the below content</li></ul><pre><strong>import </strong>android.app.Application;<br><br><strong>import </strong>com.facebook.react.ReactApplication;<br><strong>import </strong>com.facebook.react.ReactNativeHost;<br><strong>import </strong>com.facebook.react.ReactPackage;<br><strong>import </strong>com.facebook.react.shell.MainReactPackage;<br><strong>import </strong>com.facebook.soloader.SoLoader;<br><br><strong>import </strong>java.util.Arrays;<br><strong>import </strong>java.util.List;<br><br><strong>public class </strong>MainApplication <strong>extends </strong>Application <strong>implements </strong>ReactApplication {<br><br>    <strong>private final </strong>ReactNativeHost <strong>mReactNativeHost </strong>= <strong>new </strong>ReactNativeHost(<strong>this</strong>) {<br>        @Override<br>        <strong>public boolean </strong>getUseDeveloperSupport() {<br>            <strong>return </strong>BuildConfig.<strong><em>DEBUG</em></strong>;<br>        }<br><br>        @Override<br>        <strong>protected </strong>List&lt;ReactPackage&gt; getPackages() {<br>            <strong>return </strong>Arrays.&lt;ReactPackage&gt;<em>asList</em>(<br>                    <strong>new </strong>MainReactPackage(),<br>                    <strong>new </strong>CustomReactPackage()<br>            );<br>        }<br>    };<br><br>    @Override<br>    <strong>public </strong>ReactNativeHost getReactNativeHost() {<br>        <strong>return mReactNativeHost</strong>;<br>    }<br><br>    @Override<br>    <strong>public void </strong>onCreate() {<br>        <strong>super</strong>.onCreate();<br>        SoLoader.<em>init</em>(<strong>this</strong>, <em>/* native exopackage */ </em><strong>false</strong>);<br>    }<br>}</pre><ul><li>Update your “AndroidManifest.xml” with the below data</li></ul><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    package=&quot;com.ankurkushwaha.eyespy&quot;</strong>&gt;<br><br>    &lt;<strong>uses-permission android:name=&quot;android.permission.INTERNET&quot; </strong>/&gt;<br>    &lt;<strong>uses-permission android:name=&quot;android.permission.SYSTEM_ALERT_WINDOW&quot; </strong>/&gt;<br>    &lt;<strong>uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; </strong>/&gt;<br><br>    &lt;<strong>application<br>        android:name=&quot;.MainApplication&quot;<br>        android:allowBackup=&quot;true&quot;<br>        android:icon=&quot;@mipmap/ic_launcher&quot;<br>        android:label=&quot;@string/app_name&quot;<br>        android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;<br>        android:supportsRtl=&quot;true&quot;<br>        android:theme=&quot;@style/AppTheme&quot;</strong>&gt;<br>        &lt;<strong>activity<br>            android:name=&quot;.MyReactActivity&quot;<br>            android:configChanges=&quot;keyboard|keyboardHidden|orientation|screenSize&quot;<br>            android:label=&quot;@string/app_name&quot;<br>            android:windowSoftInputMode=&quot;adjustResize&quot;</strong>&gt;<br>            &lt;<strong>intent-filter</strong>&gt;<br>                &lt;<strong>action android:name=&quot;android.intent.action.MAIN&quot; </strong>/&gt;<br>                &lt;<strong>category android:name=&quot;android.intent.category.LAUNCHER&quot; </strong>/&gt;<br>            &lt;/<strong>intent-filter</strong>&gt;<br>        &lt;/<strong>activity</strong>&gt;<br>        &lt;<strong>activity android:name=&quot;com.facebook.react.devsupport.DevSettingsActivity&quot; </strong>/&gt;<br>        <br>  <br>    &lt;/<strong>application</strong>&gt;<br><br>&lt;/<strong>manifest</strong>&gt;</pre><ul><li>In your app’s build.gradle file add the React Native dependency:</li></ul><pre>dependencies { <br>   compile “com.facebook.react:react-native:+” // From node_modules. <br>}</pre><ul><li>In your project’s build.gradle file add an entry for the local React Native maven directory. Be sure to add it to the &quot;allprojects&quot; block:</li></ul><pre>allprojects {     <br>   repositories {         <br>      ...         <br>      maven {               <br>         url &quot;$rootDir/../node_modules/react-native/android&quot;                              }     <br>}     <br>... <br>}</pre><p><strong>Configure HeadlessJS task</strong></p><blockquote>Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.</blockquote><p>Its similar to creating an android service in java, just using it you can create service in javascript as well.</p><ul><li>Register the js service using the below code</li></ul><pre>import {task} from &#39;./SomeTaskName&#39;;</pre><pre>AppRegistry.registerHeadlessTask(&#39;SomeTaskName&#39;, () =&gt; task);</pre><ul><li>Then, in SomeTaskName.js:</li></ul><pre>export async function task(taskData) {</pre><pre>    console.log(&#39;BACKGROUND AUDIO&#39;)</pre><pre>}</pre><ul><li>Create a service in your base package</li></ul><pre>public class MyTaskService extends HeadlessJsTaskService {</pre><pre>@Override</pre><pre>protected</pre><pre>@Nullable</pre><pre>HeadlessJsTaskConfig getTaskConfig(Intent intent) {</pre><pre>   Log.d(&quot;MyTaskService&quot;, &quot;task invoked in java&quot;);</pre><pre>   Bundle extras = intent.getExtras();</pre><pre>   return new HeadlessJsTaskConfig(</pre><pre>      &quot;SomeTaskName&quot;,</pre><pre>      null,</pre><pre>      5000);</pre><pre>   }</pre><pre>}</pre><pre>// Register this service in AndroidManifest.xml </pre><pre>// &lt;service android:name=&quot;.MyTaskService&quot;/&gt;</pre><ul><li>Now if you start this service like any other service it will invoke the corresponding the javascript code. Here is the example for running inside the broadcast receiver.</li></ul><pre><strong>public class </strong>MyReceiver <strong>extends </strong>BroadcastReceiver {<br>    @Override<br>    <strong>public void </strong>onReceive(Context context, Intent intent) {<br>        Toast.<em>makeText</em>(context, <strong>&quot;Intent Detected.&quot;</strong>, Toast.<strong><em>LENGTH_LONG</em></strong>).show();<br><br>        context.startService(<strong>new </strong>Intent(context, MyTaskService.<strong>class</strong>));<br>        HeadlessJsTaskService.<em>acquireWakeLockNow</em>(context);<br>    }<br>}</pre><p><strong>Communication between React Native and Native code</strong></p><p>Now suppose you want to invoke a service or method defined in native code, in that case you need a mechanism to communicate b/w two. Here are the steps on how you can do that.</p><ul><li>Create your CustomModule containing your method</li></ul><pre><strong>public class </strong>ToastModule <strong>extends </strong>ReactContextBaseJavaModule {<br><br>    <strong>private static final </strong>String <strong><em>DURATION_SHORT_KEY </em></strong>= <strong>&quot;SHORT&quot;</strong>;<br>    <strong>private static final </strong>String <strong><em>DURATION_LONG_KEY </em></strong>= <strong>&quot;LONG&quot;</strong>;<br><br>    <strong>public </strong>ToastModule(ReactApplicationContext reactContext) {<br>        <strong>super</strong>(reactContext);<br>    }<br><br>    @Override<br>    <strong>public </strong>String getName() {<br>        <strong>return &quot;CustomToastAndroid&quot;</strong>;<br>    }<br><br>    @Override<br>    <strong>public </strong>Map&lt;String, Object&gt; getConstants() {<br>        <strong>final </strong>Map&lt;String, Object&gt; constants = <strong>new </strong>HashMap&lt;&gt;();<br>        constants.put(<strong><em>DURATION_SHORT_KEY</em></strong>, Toast.<strong><em>LENGTH_SHORT</em></strong>);<br>        constants.put(<strong><em>DURATION_LONG_KEY</em></strong>, Toast.<strong><em>LENGTH_LONG</em></strong>);<br>        <strong>return </strong>constants;<br>    }</pre><pre>//this @ReactMethod will be available in javascript environment<br>    @ReactMethod<br>    <strong>public void </strong>show(String message, <strong>int </strong>duration) {<br>        Log.<em>d</em>(getName(),<strong>&quot;toast called with &quot;</strong>+message);<br><br>        <em>//getReactApplicationContext().startService(new Intent(getReactApplicationContext(), MyTaskService.class));<br>        //HeadlessJsTaskService.acquireWakeLockNow(getReactApplicationContext());<br>        </em>Toast.<em>makeText</em>(getReactApplicationContext(), message, duration).show();<br>    }<br>}</pre><ul><li>Create a CustomReactPackage.java to register your module</li></ul><pre><strong>public class </strong>CustomReactPackage <strong>implements </strong>ReactPackage {<br><br>    @Override<br>    <strong>public </strong>List&lt;Class&lt;? <strong>extends </strong>JavaScriptModule&gt;&gt; createJSModules() {<br>        <strong>return </strong>Collections.<em>emptyList</em>();<br>    }<br><br>    @Override<br>    <strong>public </strong>List&lt;ViewManager&gt; createViewManagers(ReactApplicationContext reactContext) {<br>        <strong>return </strong>Collections.<em>emptyList</em>();<br>    }<br><br>    @Override<br>    <strong>public </strong>List&lt;NativeModule&gt; createNativeModules(<br>            ReactApplicationContext reactContext) {<br><br>        List&lt;NativeModule&gt; modules = <strong>new </strong>ArrayList&lt;&gt;();<br><br>        modules.add(<strong>new </strong>ToastModule(reactContext));<br><br>        <strong>return </strong>modules;<br>    }<br><br>}</pre><ul><li>Update your MainApplication file to include your CustomReactPackage</li></ul><pre><strong>private final </strong>ReactNativeHost <strong>mReactNativeHost </strong>= <strong>new </strong>ReactNativeHost(<strong>this</strong>) {<br>    @Override<br>    <strong>public boolean </strong>getUseDeveloperSupport() {<br>        <strong>return </strong>BuildConfig.<strong><em>DEBUG</em></strong>;<br>    }<br><br>    @Override<br>    <strong>protected </strong>List&lt;ReactPackage&gt; getPackages() {<br>        <strong>return </strong>Arrays.&lt;ReactPackage&gt;<em>asList</em>(<br>                <strong>new </strong>MainReactPackage(),<br>                <strong>new </strong>CustomReactPackage() //custom package is added here<br>        );<br>    }<br>};</pre><ul><li>Here are the steps to use your custom module in ReactJS</li></ul><pre>import { NativeModules } from &#39;react-native&#39;;</pre><pre>ToastAndroid = NativeModules.CustomToastAndroid;</pre><ul><li>You can also use callback to get the result of your service as well. <a href="https://facebook.github.io/react-native/docs/native-modules-android.html">https://facebook.github.io/react-native/docs/native-modules-android.html</a></li></ul><p><strong>References</strong></p><ul><li><a href="https://facebook.github.io/react-native/docs/headless-js-android.html">https://facebook.github.io/react-native/docs/headless-js-android.html</a></li><li><a href="https://facebook.github.io/react-native/docs/native-modules-android.html">https://facebook.github.io/react-native/docs/native-modules-android.html</a></li><li><a href="https://developer.android.com/studio/index.html">https://developer.android.com/studio/index.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e315bbba3814" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>