<?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 Oleksii Malitskyi on Medium]]></title>
        <description><![CDATA[Stories by Oleksii Malitskyi on Medium]]></description>
        <link>https://medium.com/@mr.malitskyi?source=rss-f0ecefcb13be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QUh8tbDYcKI81Q6HygbsVQ.jpeg</url>
            <title>Stories by Oleksii Malitskyi on Medium</title>
            <link>https://medium.com/@mr.malitskyi?source=rss-f0ecefcb13be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:31:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mr.malitskyi/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[Shared component library for ReactJS and React Native with Storybook]]></title>
            <link>https://medium.com/propertyfinder-engineering/shared-component-library-for-reactjs-and-react-native-with-storybook-e1abbe9d84cb?source=rss-f0ecefcb13be------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1abbe9d84cb</guid>
            <category><![CDATA[ui-library]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[storybook]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Oleksii Malitskyi]]></dc:creator>
            <pubDate>Mon, 31 Jan 2022 07:25:50 GMT</pubDate>
            <atom:updated>2022-02-04T09:02:25.736Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Shared component library for ReactJS and React Native with Storybook" src="https://cdn-images-1.medium.com/max/1024/1*6qm258DqLhFY6uigU6rkNw.jpeg" /></figure><p>A few years ago the idea of writing reusable code for different platforms was a “little” wild, right? But luckily now, in 2022, we have a lot of amazing tools that let us do this in quite a simple way. And one of the best use cases for writing reusable code is building a component UI library that is a great way to enforce design standards across an organisation or codebase. In this article, we’ll be taking a look at React Native, React JS and Storybook to try to create a reusable library for WEB and Mobile platforms.</p><h3>What is React Native?</h3><p>Let’s start by determining what React Native is. It’s a JavaScript framework that lets you create truly native apps for iOS and Android. This technology, similar to React for the Web, is written using a combination of JavaScript and XML markup, known as JSX. In other words, Web Developers, can now write mobile applications that look and feel truly “native,” all from the comfort of a JavaScript library that they already know and love. That’s the key thing that will help us in building the reusable library boilerplate.</p><h3>What is a Storybook?</h3><p>The next key piece of our application is <a href="https://storybook.js.org/">Storybook</a> — a JavaScript tool that allows us to create and organise UI systems making both the building process and documentation more efficient and easier to use.</p><figure><img alt="Storybook" src="https://cdn-images-1.medium.com/max/1024/0*rhG2Tk1RcUF4oXnP" /></figure><p>For our application, we will use a Storybook for presenting the UI of our components and how they work.</p><h3>The concept</h3><p>Great, since we are all clear on the techstack that we are going to use, let’s dive more into the concept of our future application. The first idea that comes to mind when you are thinking about the “write once use everywhere” concept is <a href="https://github.com/necolas/react-native-web">react-native-web</a>. This is an amazing library that lets you run React Native components and APIs on the web using React DOM (in case you created your React Native app using <a href="https://expo.dev/">Expo</a>, then this library will be included by default). A problem that could surface is a potential bottleneck in the development process, where all will be dependent on the native Engineers only, and the inability to impact or improve the web-version of components separately.</p><p>In order to overcome these limitations and add a bit of flexibility to the process, we will create a monorepo that will support ReactJS and React Native at the same time. Where the React Native will be handling the load and build of the mobile platform application using .android, .ios, or .native files. And React JS — .web files for the WEB application.</p><p>We will separate the presentation layer of the components to component.web.tsx, component.native.tsx and at the same time will try to reuse the logical layer using container components — component.container.tsx that we are going to implement via the “<a href="https://reactjs.org/docs/render-props.html">render props</a>” technique. And finally, we will connect the storybook to our applications to let us build and document UI components in isolation for WEB and native platforms.</p><p>As part of this tutorial, we will be following the folder structure that is being generated by the Expo, but in your project, you can use any structure you want.</p><p>The final version of this POC you can find <a href="https://github.com/mrMalitsky/ui-library-react-and-react-native">here</a>.</p><h3>Setting up the project</h3><p>Let’s dive into the actual implementation of the shared component library. We will be using the Expo for setting up the initial React Native application with Typescript.</p><p>First, we need to add Expo CLI globally by running:</p><pre>yarn global add expo-cli</pre><p>Now we can create our empty Expo project:</p><pre>expo init ui-library</pre><p>And select blank (TypeScript) or blank option if you want application just with JS.</p><p>Next, navigate to the project folder:</p><pre>cd ui-library</pre><p>And initiate the installation of react Storybook:</p><pre>npx -p @storybook/cli sb init --type react</pre><p>Install the Storybook React Native package:</p><pre>yarn add -D @storybook/react-native</pre><p>While using the storybook for React Native, I found myself repeatedly manually creating a file with imports for all of my stories. To solve this we will be using <a href="https://github.com/elderfo/react-native-storybook-loader">react-native-storybook-loader</a>:</p><pre>yarn add react-native-storybook-loader -D</pre><blockquote>Note: If you prefer to set things up yourself, you can follow the <a href="https://github.com/storybookjs/react-native/blob/master/app/react-native/docs/manual-setup.md">manual setup</a> and skip to <a href="https://medium.com/@mr.malitskyi/shared-component-library-for-reactjs-and-react-native-with-storybook-e1abbe9d84cb#a06c">Creating component</a> step.</blockquote><p>Update the script section in your package.json in order to run pre-storybook script before starting React native application:</p><pre>{...</pre><pre>  &quot;scripts&quot;: {</pre><pre>    ...</pre><pre>    &quot;start-native&quot;: &quot;yarn prestorybook &amp;&amp; expo start&quot;,</pre><pre>    &quot;prestorybook&quot;: &quot;rnstl&quot;,</pre><pre>    ...</pre><pre>  }</pre><pre>}</pre><p>The next step in setting up a react-native-storybook-loader is the configuration in which directory to look for native stories. In the package.json file add the following section:</p><pre>{...<br>  &quot;config&quot;: {</pre><pre>    &quot;react-native-storybook-loader&quot;: {</pre><pre>      &quot;searchDir&quot;: [&quot;./stories&quot;],</pre><pre>      &quot;pattern&quot;: &quot;**/*.stories.native.tsx&quot;,</pre><pre>      &quot;outputFile&quot;: &quot;./storybook/storyLoader.js&quot;</pre><pre>    }</pre><pre>  },<br>}</pre><p>yarn prestorybook will search in the application for the stories files following the pattern that you specified in thepackage.json and automatically generate the list of stories files in the storyLoader.js file.</p><p>Finally, modify your App.tsx or App.js file to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85d0d395ff828c09faa3c1a0b854be09/href">https://medium.com/media/85d0d395ff828c09faa3c1a0b854be09/href</a></iframe><blockquote>Note: After the first run of the application the storyLoader.js file will be generated.</blockquote><h3>Creating component</h3><p>First, let’s create a components/button folder and add a props interface file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ce71b532d15621b3f8dd3a8e2fcc959/href">https://medium.com/media/8ce71b532d15621b3f8dd3a8e2fcc959/href</a></iframe><p>Then we can add our native component button.native.tsx</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18958bae218f49b52cf8a87b8aef6899/href">https://medium.com/media/18958bae218f49b52cf8a87b8aef6899/href</a></iframe><h3>Making stories</h3><p>Now that we have a component in our application we can create a story for it. Clean everything from the stories folder and add the simplest type of story for the button component button.stories.native.tsx that looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/430a9203f30e2dcd6d5becc41b7b27ed/href">https://medium.com/media/430a9203f30e2dcd6d5becc41b7b27ed/href</a></iframe><p>Now, you can start the application by running:</p><pre>yarn start-native</pre><p>Here is the result that you can see:</p><figure><img alt="Native component preview" src="https://cdn-images-1.medium.com/max/732/1*lTStoIgmMomw7_7eT_dqUQ.png" /><figcaption>Native component preview</figcaption></figure><h3>Adding WEB support</h3><p>Install the expo webpack config for the web version of the library, so we can add unimodules support and serve the ReactJS application separately from the React Native.</p><pre>yarn add -D @expo/webpack-config</pre><p>Create a <a href="https://github.com/expo/examples/blob/master/with-storybook/.storybook/webpack.config.js">custom webpack config</a>:</p><pre>mkdir .storybook</pre><p>and</p><pre>touch .storybook/webpack.config.js</pre><p>And add following content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e58094647e4535e5086beba75afa9c93/href">https://medium.com/media/e58094647e4535e5086beba75afa9c93/href</a></iframe><p>Then modify the stories section in .storybook/main.js file to use only web specific files for the browser version of the library:</p><pre>{...<br>  &quot;stories&quot;: [</pre><pre>    &quot;../stories/**/*.stories.web.@(js|jsx|ts|tsx|mdx)&quot;</pre><pre>  ],<br>}</pre><p>Now let’s create ReactJS version of our component button.web.tsx in the /components.button folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73ed5badc0f27463f290e940be97f7e4/href">https://medium.com/media/73ed5badc0f27463f290e940be97f7e4/href</a></iframe><p>And a story file for it button.stories.web.tsx in the /stories folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4841034f0aba13e8cf8e508147bf4180/href">https://medium.com/media/4841034f0aba13e8cf8e508147bf4180/href</a></iframe><p>Now you can run:</p><pre>yarn start-storybook -p 6006</pre><p>And see the result:</p><figure><img alt="WEB componet preview" src="https://cdn-images-1.medium.com/max/1024/0*7N3QPNOKe8B1HXJP" /><figcaption>WEB component preview</figcaption></figure><h3>Adding reusable components</h3><p>Until this point, there wasn’t much reusable stuff between applications, but now let’s create the container component that will hold shared logical parts for both our.native and .web components.</p><p>Create file button.container.tsx with the following content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea955833abbaee33c81661b68b61494f/href">https://medium.com/media/ea955833abbaee33c81661b68b61494f/href</a></iframe><p>This is a point of our application where we should connect our state management system, data fetching, or any other logical part of the application. That is commonly supported in ReactJS and React Native applications.</p><p>So now we can update our stories files to see the components with reusable logic:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb284ddcc1cc8b6082e388b72dbca517/href">https://medium.com/media/bb284ddcc1cc8b6082e388b72dbca517/href</a></iframe><p>And</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67c16ca352b46417271f87fa7d022008/href">https://medium.com/media/67c16ca352b46417271f87fa7d022008/href</a></iframe><h3>Sharing styles</h3><p>In order to share styles between the platforms you can simply create style.ts file:</p><pre>export const <strong><em>Style </em></strong>= {</pre><pre>  &quot;fontSize&quot;: 15,</pre><pre>  &quot;paddingBottom&quot;: 20,</pre><pre>  &quot;paddingTop&quot;: 50,</pre><pre>  &quot;color&quot;: &quot;#01488b&quot;,</pre><pre>  &quot;textAlign&quot;: &quot;center&quot;</pre><pre>}</pre><p>And add these lines of the code to the .native components to use a style:</p><pre>const styles = StyleSheet.create({</pre><pre>  title: <strong><em>Style</em></strong></pre><pre>})</pre><p>And for the web version pass it directly to the style property:</p><pre>&lt;button style={<strong><em>Style</em></strong>}&gt;&lt;/button&gt;</pre><p>It would even be possible to extend the object to achieve two separate styles based on a common shared one. However, sharing styles is something that might be too hard to maintain, perhaps requiring even more time than handling two completely separate style definitions. Therefore, if you decide to venture into this quest for unification, be aware that it might not be that rewarding.</p><h3>To Conclude</h3><p>We’ve set-up an application that lets you create native and web components with the ability to share logical parts of it. At Property Finder, we have already benefited from this technique and we are convinced that it is a simple and very effective way of creating the cross-platform features that helps us to save time and money. We hope that you find this useful for your application as well.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1abbe9d84cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/propertyfinder-engineering/shared-component-library-for-reactjs-and-react-native-with-storybook-e1abbe9d84cb">Shared component library for ReactJS and React Native with Storybook</a> was originally published in <a href="https://medium.com/propertyfinder-engineering">Property Finder Engineering and Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>