<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Douglas Jose</title>
    <description>The latest articles on DEV Community by Douglas Jose (@douglasjose).</description>
    <link>https://dev.to/douglasjose</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F280774%2F4e2f5c04-9274-4f17-9b77-4eff9ab9aec8.png</url>
      <title>DEV Community: Douglas Jose</title>
      <link>https://dev.to/douglasjose</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/douglasjose"/>
    <language>en</language>
    <item>
      <title>Building React Components</title>
      <dc:creator>Douglas Jose</dc:creator>
      <pubDate>Wed, 27 Nov 2019 06:46:24 +0000</pubDate>
      <link>https://dev.to/douglasjose/building-react-components-4oik</link>
      <guid>https://dev.to/douglasjose/building-react-components-4oik</guid>
      <description>&lt;p&gt;I have a React project, created with &lt;code&gt;npx create-react-app&lt;/code&gt; where I implemented a handful React Components. I don't really see this project as an "React application", as it's just a personal library of Components I consume in another project, an HTML web application rendered using server-side technologies. My goal  is to gradually replace parts of this application with React components. I don't really envision it becoming a single React application, my plan is just to replace the parts I think make sense to be developed with React.&lt;/p&gt;

&lt;p&gt;I have no issue implementing these components - I'm using Storybook to organize the independent modules. But I'm struggling with the build process.&lt;/p&gt;

&lt;p&gt;If I run &lt;code&gt;npm run build&lt;/code&gt; I create a single application, based on the original React application code bootstrapped by &lt;code&gt;create-react-app&lt;/code&gt;, which I essentially abandoned in favor of the Storybook setup. If I add the files generated by &lt;code&gt;npm run build&lt;/code&gt; my project, I can't get React to render my components properly.&lt;/p&gt;

&lt;p&gt;I managed to get a manual build process to work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In my HTML project I add &lt;a href="https://unpkg.com/react@16/umd/react.production.min.js"&gt;https://unpkg.com/react@16/umd/react.production.min.js&lt;/a&gt; and &lt;a href="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"&gt;https://unpkg.com/react-dom@16/umd/react-dom.production.min.js&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;For each of my React components source files, I run &lt;code&gt;npx babel --presets react-app/prod src/MyComponent.js -o build/mycomponent.js&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Then I combine all the &lt;code&gt;npx babel&lt;/code&gt; outputs in a single &lt;code&gt;components.js&lt;/code&gt; file, adjusting some repeated functions that appear on the top of all files, and suppressing the &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;export&lt;/code&gt; statements.&lt;/li&gt;
&lt;li&gt;I load the &lt;code&gt;component.js&lt;/code&gt; file in my HTML project, and I can create my components using plain JS:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ReactDOM.render(
    React.createElement(MyComponent, {param: value}, null),
    document.getElementById('myComponent')
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Is there a better process to build my components to a single JS file I could consume in my HTML application? &lt;/p&gt;

</description>
      <category>help</category>
      <category>react</category>
    </item>
  </channel>
</rss>
