<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>react Archives - Yumasoft</title>
	<atom:link href="https://blog.yumasoft.pl/tag/react/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.yumasoft.pl/tag/react/</link>
	<description>Software development blog</description>
	<lastBuildDate>Sun, 01 Jan 2023 14:54:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.yumasoft.pl/wp-content/uploads/2021/05/cropped-yumasoft_icon_transparent-32x32.png</url>
	<title>react Archives - Yumasoft</title>
	<link>https://blog.yumasoft.pl/tag/react/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Technologies We Are Looking At In 2023</title>
		<link>https://blog.yumasoft.pl/2023/01/technologies-we-are-looking-at-in-2023/</link>
					<comments>https://blog.yumasoft.pl/2023/01/technologies-we-are-looking-at-in-2023/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sun, 01 Jan 2023 14:54:15 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[2023]]></category>
		<category><![CDATA[2023 predictions]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[artificial intelligence]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[azure]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[google cloud]]></category>
		<category><![CDATA[react]]></category>
		<category><![CDATA[saas]]></category>
		<category><![CDATA[technologies 2023]]></category>
		<guid isPermaLink="false">https://blog.yumasoft.pl/?p=984</guid>

					<description><![CDATA[<p>As 2022 approaches its end, we can start making some summaries. By this opportunity, we have recently had a series of internal, in-person meetings. One of them included brainstorming sessions with one of our largest customers. The product of those meetings are technological perspectives for Yumasoft and our clients in the coming months. In this&#8230;</p>
<p>The post <a rel="nofollow" href="https://blog.yumasoft.pl/2023/01/technologies-we-are-looking-at-in-2023/">Technologies We Are Looking At In 2023</a> appeared first on <a rel="nofollow" href="https://blog.yumasoft.pl">Yumasoft</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>As 2022 approaches its end, we can start making some summaries. By this opportunity, we have recently had a series of internal, in-person meetings. One of them included brainstorming sessions with one of our largest customers.</p>



<p>The product of those meetings are technological perspectives for Yumasoft and our clients in the coming months. In this article, I&#8217;d like to share some of the technologies we are going to look into in 2023.</p>



<span id="more-984"></span>



<h2 class="wp-block-heading">AI</h2>



<p>Artificial Intelligence is one of the technologies that’s been getting a lot of hype recently. Mostly thanks to OpenAI opening its GPT-3&nbsp;<a href="https://beta.openai.com/playground">playground</a>&nbsp;and&nbsp;<a href="https://chat.openai.com/chat">chat</a>. This is all fun, but companies started looking into how to use this in their businesses. We are also looking on how to leverage these new findings in AI to make our customers’ businesses easier. We think that AI can make end users’ life smoother, allowing them to focus on what is the most important.</p>



<p>The fact is that in many applications we develop for our clients, there is a lot of data. We have quite rich experience in developing various document and quality management systems. The data in those systems can be generally classified as documents. The documents contain tons of information. This information is currently manually enriched with metadata by the end users. In AI, we see a huge potential to automate this part of people’s jobs.&nbsp;<a href="https://en.wikipedia.org/wiki/Natural_language_processing">NLP</a>&nbsp;is very promising in this manner. It is also worth looking into the technologies like&nbsp;<a href="https://www.usehaystack.io/">Haystack</a>&nbsp;and&nbsp;<a href="https://dotnet.microsoft.com/en-us/apps/machinelearning-ai/ml-dotnet">ML.NET</a>. The goal is that the end users can focus on their most important tasks, i.e. providing business value to companies they work for. Manual work should be limited to supervision and “teaching” the AI algorithm to perform better.</p>



<p>At Yumasoft, one of the technologies we are looking at in 2023, is definitely Artificial Intelligence. We think it’s a way forward in most applications of software development, especially those including big data. What’s more, implementing AI is a great marketing leverage <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h2 class="wp-block-heading">Guide-based forms/wizards</h2>



<p>Diving into AI, we got inspired by how algorithms can help users fill the data online. We think that instead of presenting the end user with an old-school form containing dozens of input fields, we can ask him/her a few relevant questions and&nbsp;<em>prefill</em>&nbsp;the form based on the answers.</p>



<p>Firstly, when performing an operation in the system, the user is asked several questions in a wizard/step-by-step guide form. Finally, our algorithm analyses the user’s answers and present the user with a&nbsp;<em>prefilled</em>&nbsp;HTML form. The user’s ultimate role is to verify the data. What’s more, if the form’s values are corrected manually by the user, the algorithm can learn from those editions to propose better values in the future.</p>



<p>At Yumasoft, we think it’s better to sometimes lead the users by hand, instead of presenting them with complex, old-school forms. We’ll be exploring such ideas in the coming months.</p>



<h2 class="wp-block-heading">Minimal UIs</h2>



<p>Nowadays, we are generally overstimulated. The marketing is omnipresent. Still remember these 3-weeks-long Black Friday sales? And the week-long Cyber Monday ones just after? We don’t want our applications to make people even more distracted in today’s world.</p>



<p>Similarly to simplifying the forms, we think creating&nbsp;<a href="https://en.wikipedia.org/wiki/KISS_principle">KISS</a>&nbsp;UIs is crucial. We can also call them the&nbsp;<em><a href="https://uxdesign.cc/a-guide-to-the-modern-minimal-ui-style-531ac1e9fbfe">minimal UIs</a></em>.</p>



<p>For instance: let’s assume we have a dashboard. The dashboard shows many things: new procedures, unread documents, some actions to take, people to call, notifications, company events… Usually, you as a user are only interested in what you actually need to do &#8211; now and today. The typical dashboard may contain too much information to easily spot the really important things requiring your immediate action. A solution to that could be presenting a simple indicator, like a colored, pulsating dot in a place that is central to the user:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="370" height="215" src="https://blog.yumasoft.pl/wp-content/uploads/2023/01/1_Certifeye_dashboard_dot.png" alt="Technologies we are looking at in 2023 - pulsating dot marking tasks to be done in a dashboard for the user" class="wp-image-987" srcset="https://blog.yumasoft.pl/wp-content/uploads/2023/01/1_Certifeye_dashboard_dot.png 370w, https://blog.yumasoft.pl/wp-content/uploads/2023/01/1_Certifeye_dashboard_dot-300x174.png 300w" sizes="(max-width: 370px) 100vw, 370px" /></figure>
</div>


<p>The goal is to clearly see, in a single place, whether you have something to do for now or not. This is the only thing you&#8217;re really interested in.</p>



<p>Such an approach simplifies working with the system and saves a lot of users’ time. It is also based on showing as little information as possible to get the job done.</p>



<h2 class="wp-block-heading">React</h2>



<p>As per&nbsp;<a href="https://2021.stateofjs.com/en-US/libraries/front-end-frameworks">The State of JS 2021 survey</a>, React is currently the most popular front-end framework on the market. We’ve already been working with it for a long time, but it seems that we will be exploring React even more. At the moment, React is our default choice for new projects.</p>



<h2 class="wp-block-heading">SaaS</h2>



<p>For some of our customers, we are still maintaining heavy desktop clients, including Windows applications. These programs require quite good hardware, as well as manual installation and maintenance. If the application we develop makes use of external desktop tools like Microsoft Office, this also adds the costs of licensing for every end user.</p>



<p>As a consequence, the businesses are expecting to move the software into the cloud.&nbsp;<a href="https://en.wikipedia.org/wiki/Software_as_a_service">SaaS</a>&nbsp;looks like the preferred model. Web apps only require a modern web browser and Internet access to be used. Additionally, end users don’t need to worry about licensing. Most of UI and other frameworks are licensed per application or per developer. This is a huge difference to desktop applications, where every end user must possess a proper license for the operating system and used programs.</p>



<p>Finally, it’s much easier to maintain SaaS-based systems. The updates are provided to everyone in a timely manner. It adds some complexity on the development and infrastructure, like keeping the backwards compatibility, but it seems to be worth the effort. Heavy clients are fading away and becoming unwanted in most use cases.</p>



<h2 class="wp-block-heading">Cloud</h2>



<p>Last but not least, at Yumasoft we are looking to more integration with cloud services like&nbsp;<a href="https://azure.microsoft.com/en-us/">Microsoft Azure</a>,&nbsp;<a href="https://aws.amazon.com/">AWS</a>&nbsp;and&nbsp;<a href="https://cloud.google.com/">Google Cloud</a>. This goes together with betting on SaaS. Delegating the infrastructure to the cloud makes the maintenance much easier and smoother. Moreover, cloud computing services provide AI platforms and tools. The examples include&nbsp;<a href="https://cloud.google.com/document-ai">Google’s Document AI</a>&nbsp;or&nbsp;<a href="https://azure.microsoft.com/en-us/products/search/">Azure Cognitive Search</a>.</p>



<p>Of course, moving the data into the cloud comes with challenges. Data anonymization and security should be of a great concern here.</p>



<h2 class="wp-block-heading">Summary</h2>



<p>All of us &#8211; the technical teams as Yumasoft, our clients, their customers and finally &#8211; the end users &#8211; will have to go through a transformation which is happening right now. AI will bring a lot of improvements into most areas of our lives. Cloud computing will challenge all of us in terms of privacy and willingness to share our data with external companies. Will we trust them? Will we decide to go with the innovation flow, sometimes sacrificing our current beliefs? <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f914.png" alt="🤔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>We are so excited about the coming months. We look forward to 2023 and can’t wait to get our hands on these technologies! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a rel="nofollow" href="https://blog.yumasoft.pl/2023/01/technologies-we-are-looking-at-in-2023/">Technologies We Are Looking At In 2023</a> appeared first on <a rel="nofollow" href="https://blog.yumasoft.pl">Yumasoft</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.yumasoft.pl/2023/01/technologies-we-are-looking-at-in-2023/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Migrating JavaScript React App to TypeScript</title>
		<link>https://blog.yumasoft.pl/2021/06/migrating-javascript-react-app-to-typescript/</link>
					<comments>https://blog.yumasoft.pl/2021/06/migrating-javascript-react-app-to-typescript/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Mon, 28 Jun 2021 07:15:00 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript to typescript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[react]]></category>
		<category><![CDATA[reactjs]]></category>
		<category><![CDATA[ts]]></category>
		<category><![CDATA[typescript]]></category>
		<guid isPermaLink="false">https://blog.yumasoft.pl/?p=342</guid>

					<description><![CDATA[<p>In one of our biggest projects, we develop and maintain a React web application. Last year, we decided to migrate it to TypeScript. How did it go? How did we migrate JavaScript to TypeScript? Was it worth it? What struggles we met and are we still having any issues? I&#8217;ll try to address these questions&#8230;</p>
<p>The post <a rel="nofollow" href="https://blog.yumasoft.pl/2021/06/migrating-javascript-react-app-to-typescript/">Migrating JavaScript React App to TypeScript</a> appeared first on <a rel="nofollow" href="https://blog.yumasoft.pl">Yumasoft</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In one of our biggest projects, we develop and maintain a React web application. Last year, we decided to migrate it to TypeScript. How did it go? How did we migrate JavaScript to TypeScript? Was it worth it? What struggles we met and are we still having any issues? I&#8217;ll try to address these questions in this article.</p>



<p><em>Disclaimer: I&#8217;m not describing the migration process step-by-step or TypeScript itself in this article. You can find many resources on that online, including <a href="https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html">official TS docs</a>.</em></p>



<span id="more-342"></span>



<h2 class="wp-block-heading">JavaScript to TypeScript migration strategy</h2>



<p>If you search online, you will find many possible strategies of migrating JavaScript to TypeScript. We considered two of them:</p>



<ul class="wp-block-list"><li>converting the whole JavaScript codebase to TypeScript at once</li><li>starting to use TypeScript compiler and migrate step-by-step.</li></ul>



<p>After a short discussion, we decided to go with the <strong>step-by-step migration strategy</strong>. Why? First, it&#8217;s less time-consuming. Today, we know that it would kill us if we decided to convert all our JS codebase to TS at once. It would also freeze our codebase for a while &#8211; until every <code>.JS(X)</code> file is renamed to <code>.TS(X)</code> and all compile errors are fixed.</p>



<p>Thanks to the fact that TypeScript is a superset of JavaScript, <code>.JS(X)</code> and <code>.TS(X)</code> files can co-exist even if you switch to use TypeScript compiler. That&#8217;s because <strong>every JavaScript is also a valid TypeScript code</strong> and TS compiler can handle it.</p>



<p>That&#8217;s very comfortable. Just think about that &#8211; <strong>you can switch your project to TypeScript without actually having to change any code</strong>. We decided to immediately re-write a few of our recently-added functionalities to TypeScript and convert the rest gradually.</p>



<h2 class="wp-block-heading">What TypeScript gave us</h2>



<p>Before I tell you about the struggles, I want to really <strong>encourage you to migrate JavaScript to TypeScript</strong>. After 1 year since we switched to TypeScript, I&#8217;m telling you <strong>it&#8217;s the best thing you can do to your web app</strong> ?</p>



<p>Let&#8217;s see what you&#8217;ll gain if you decide to migrate JavaScript to TypeScript.</p>



<h3 class="wp-block-heading">Types in new code</h3>



<p>As soon as you switch your compiler to <em>ts-loader</em>, you can start creating files with TypeScript extensions (<code>.TS</code>, <code>.TSX</code>). It means that all your new code can now leverage types:</p>



<script src="https://gist.github.com/dsibinski/3e82afea66834d58d9c146213978af83.js"></script>



<p>Enjoy ?</p>



<h3 class="wp-block-heading">Typing information for existing libraries</h3>



<p>Have you been wondering what about the external libraries you are already using? How to get types for them? I was thinking exactly about this before migration.</p>



<p>It turns out that after you migrate JavaScript to TypeScript, most of the <code>npm</code> packages you use already have built-in typing information. You can check it on your package&#8217;s <code>npm</code> page:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="804" height="158" src="https://blog.yumasoft.pl/wp-content/uploads/2021/06/npm_typescript_icon.png" alt="" class="wp-image-350" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/06/npm_typescript_icon.png 804w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/npm_typescript_icon-300x59.png 300w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/npm_typescript_icon-768x151.png 768w" sizes="(max-width: 804px) 100vw, 804px" /></figure></div>



<p>If it doesn&#8217;t, you can try installing <code>npm</code> package called &#8220;@types/your_library_name&#8221;, e.g. <code>npm i @types/backbone</code>.</p>



<p>As a last resort, you can <a href="https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html">create the declaration files yourself</a>.</p>



<h3 class="wp-block-heading">JavaScript-TypeScript coexistence</h3>



<p>A huge benefit of TypeScript is that JavaScript code can co-exist with it. If you are like we were a year ago, with a lot of legacy JavaScript code and are afraid of switching to TS &#8211; don&#8217;t be. TypeScript makes it very easy to maintain your JS codebase or even mix it altogether.</p>



<p>There are no issues in using JavaScript code in TypeScript and otherwise. You can even <a href="https://blog.yumasoft.pl/2021/06/how-to-use-javascript-component-in-react-component/">use JS components in TypeScript</a>. We used to have a <code>services.js</code> file where we kept &#8220;services&#8221; exported as follows:</p>



<script src="https://gist.github.com/dsibinski/91250a9da08780129b7dd4e7b056f62c.js"></script>



<p>After migrating it to TypeScript (meaning renaming to <code>services.ts</code>) it turns out that these two definitions can co-exist, even in the same file:</p>



<script src="https://gist.github.com/dsibinski/13b1ba20c4c7fb03171550cbd1b04f0c.js"></script>



<p>As you can see, we added typing information to the legacy <code>StockService</code> as well. That&#8217;s because we have <code>noImplicitAny</code> enabled in our <a href="https://www.typescriptlang.org/tsconfig/#noImplicitAny">TypeScript configuration</a>. It doesn&#8217;t allow leaving any variables which are of <code>any</code> type. In any case, if you don&#8217;t know what type to use for a given variable/function, you can always type it explicitly as <code>any</code>, while moving the new code to fully-typed equivalents. That&#8217;s the power of TypeScript ?</p>



<h3 class="wp-block-heading">Compile errors</h3>



<p>I should have started with that! It might be obvious, but not for people who only worked with JavaScript on the frontend before ? Sure, you could get suggestions and warnings with <a href="https://eslint.org/">ESLint</a>, but that&#8217;s not the same as really enforced types checking on compilation level:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="804" height="141" src="https://blog.yumasoft.pl/wp-content/uploads/2021/06/TypeScript_webpack_compilation_error.png" alt="" class="wp-image-358" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/06/TypeScript_webpack_compilation_error.png 804w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/TypeScript_webpack_compilation_error-300x53.png 300w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/TypeScript_webpack_compilation_error-768x135.png 768w" sizes="(max-width: 804px) 100vw, 804px" /></figure></div>



<h3 class="wp-block-heading">Many TS compiler options</h3>



<p>TypeScript compiler has many useful <a href="https://www.typescriptlang.org/tsconfig#noImplicitAny">configuration options</a>. If you want to support JavaScript alongside TypeScript, you should enable <code>allowJs</code>. We have already mentioned the <code>noImplicitAny</code> setting that forces you to always explicitly specify types in your code. There&#8217;s much more stuff helpful in various scenarios of JS-TS migration. We were having some issues with imports from modules without default exports &#8211; enabling <code>allowSyntheticDefaultImports</code> saved us there.</p>



<p>What I&#8217;d like to emphasize here is that TypeScript compiler is really helpful ? It allows you to set your &#8220;typing&#8221; level by enforcing less or more rules. Thanks to that, you can slowly move towards more strict type checking rules like <code>noImplicitAny</code>. You&#8217;re not forced to do that from the beginning.</p>



<h3 class="wp-block-heading">Better coding experience</h3>



<p>This is definitely the best thing about TypeScript. It just feels more right to use it than coding in plain JavaScript. I see no reason to start a new project with vanilla JS today. I&#8217;d say even more &#8211; I see no reason to not migrate your JavaScript app to TypeScript. The sooner, the better!</p>



<p>You can catch your errors earlier. No need to debug the code to see if the property you used actually exists on an object. Your IDE gives you code completion suggestions. It&#8217;s a pure pleasure ?</p>



<h2 class="wp-block-heading">Migration challenges</h2>



<p>Of course, we met some challenges during migration. I don&#8217;t call them issues, because they are all manageable. Many people have already done those things, so you can find solutions to almost any issue online. Let&#8217;s see what we had to overcome.</p>



<h3 class="wp-block-heading">webpack configuration</h3>



<p>If there&#8217;s something I don&#8217;t like about web development, it&#8217;s definitely <a href="https://webpack.js.org/">webpack.</a>.. This is a typical &#8220;fighting with machines&#8221; case. Poor documentation, lack of well-described solutions online and some specificity in every project.</p>



<p>We had problems with <code>babel-loader</code> which we used to transpile JavaScript files before switching to TypeScript. Initially, afraid of introducing a regression, we wanted to keep <code>babel-loader</code> for legacy JS files. We couldn&#8217;t make it work, so we decided to switch completely to <code>ts-loader</code> for all files (including JavaScript ones).</p>



<p>Next issue was a lack of proper source maps and problems in debug mode. The breakpoints were often not hit. After a bit of searching and trial-error sessions, we found a solution. It was necessary to modify <code>webpack.config.js</code> and set <code>devtool</code> webpack setting to <code>eval-source-map</code>. We also had to use <a href="https://www.npmjs.com/package/source-map-loader">source-map-loader</a> for JavaScript files. Finally, this webpack configuration solved the debugging problems:</p>



<script src="https://gist.github.com/dsibinski/2cb3c4c10fe63a9020508c20fa31eef3.js"></script>



<p>You need to be really patient with webpack&#8230; But if you have already worked with it, I guess you know that very well ?</p>



<h3 class="wp-block-heading">Adding types to legacy JS code</h3>



<p>Adding types information with <code>noImplicitAny</code> set to <code>true</code> is sometimes challenging. Especially if you have some bigger JS files with no typing information at all. Sometimes you need to search for function&#8217;s calls to find out of what types are its parameters. In other cases, you might need to run your app and see that at runtime ? </p>



<p>Fortunately, as we already said, TypeScript doesn&#8217;t force you doing that. You can play with <a href="https://www.typescriptlang.org/tsconfig#noImplicitAny">tsconfig</a> or use <a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-6.html#suppress-errors-in-ts-files-using--ts-ignore-comments">@ts-ignore</a> as a last resort. </p>



<h3 class="wp-block-heading">Handling libraries without types</h3>



<p>Some of the libraries we used don&#8217;t provide any typing information. It makes working with them a bit difficult, especially if your TS compiler is already configured in a bit stricter mode. In such case, you might get an error similar to the following one:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="184" src="https://blog.yumasoft.pl/wp-content/uploads/2021/06/formio_missing_types-1024x184.png" alt="" class="wp-image-365" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/06/formio_missing_types-1024x184.png 1024w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/formio_missing_types-300x54.png 300w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/formio_missing_types-768x138.png 768w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/formio_missing_types.png 1062w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>Your options here are to either write the declaration files yourself, or import the library differently. You can, for instance, <code>require</code> it:</p>



<pre class="wp-block-code"><code>const FormIO = require('react-formio');</code></pre>



<p>and then use this <code>FormIO</code> variable which is typed as <code>any</code>. Again &#8211; that works because of TypeScript&#8217;s flexibility, but might not be very comfortable to live with.</p>



<h2 class="wp-block-heading">Migrate JavaScript to TypeScript &#8211; should I do it?</h2>



<p>Of course! There&#8217;s only one right answer. Don&#8217;t wait too long &#8211; start being more productive with TypeScript as soon as you can ? Believe me &#8211; you will not regret it.</p>
<p>The post <a rel="nofollow" href="https://blog.yumasoft.pl/2021/06/migrating-javascript-react-app-to-typescript/">Migrating JavaScript React App to TypeScript</a> appeared first on <a rel="nofollow" href="https://blog.yumasoft.pl">Yumasoft</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.yumasoft.pl/2021/06/migrating-javascript-react-app-to-typescript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Use JavaScript Component in React Component</title>
		<link>https://blog.yumasoft.pl/2021/06/how-to-use-javascript-component-in-react-component/</link>
					<comments>https://blog.yumasoft.pl/2021/06/how-to-use-javascript-component-in-react-component/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Mon, 14 Jun 2021 10:27:10 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[react]]></category>
		<category><![CDATA[typescript]]></category>
		<guid isPermaLink="false">https://blog.yumasoft.pl/?p=266</guid>

					<description><![CDATA[<p>We recently run into a problem of having to display a vanilla JavaScript component in a React component. This component exposes a static method to render itself, like many of pure JS components do. In a &#8220;normal&#8221; JavaScript context it would be very easy to just call such a method, providing a DOM element to&#8230;</p>
<p>The post <a rel="nofollow" href="https://blog.yumasoft.pl/2021/06/how-to-use-javascript-component-in-react-component/">How to Use JavaScript Component in React Component</a> appeared first on <a rel="nofollow" href="https://blog.yumasoft.pl">Yumasoft</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>We recently run into a problem of having to display a vanilla JavaScript component in a React component. This component exposes a static method to render itself, like many of pure JS components do. In a &#8220;normal&#8221; JavaScript context it would be very easy to just call such a method, providing a DOM element to render itself into. However, when you want to render such a document as a part of your React component, this becomes a bit tricky. Read on to see how we solved this issue.</p>



<span id="more-266"></span>



<h2 class="wp-block-heading">Context</h2>



<p>In our case, the component we wanted to render was <a href="https://ckeditor.com/docs/ckeditor5/latest/index.html" target="_blank" rel="noreferrer noopener">CKEditor5</a>. It&#8217;s a tiny and simple WYSIWYG editor.</p>



<p>Its documentation gives the following <a href="https://ckeditor.com/docs/ckeditor5/latest/api/module_editor-classic_classiceditor-ClassicEditor.html#static-function-create" target="_blank" rel="noreferrer noopener">example</a> on how to render the editor using a static <code>create</code> function:</p>



<script src="https://gist.github.com/dsibinski/dea4eeee7dc9d19cfca3379205375c64.js"></script>



<p>In our application, we have a React function component:</p>



<script src="https://gist.github.com/dsibinski/97084ba0330c51281fa7d6c434c87282.js"></script>



<p>The goal is to render the <code>ckeditor</code> component within the <code>div</code> with id <code>my-ckeditor</code>.</p>



<h2 class="wp-block-heading">Can I call the component&#8217;s <em>create</em> function in React component?</h2>



<p>The first idea that came to my mind was to somehow call the static<strong> </strong><code>create</code><strong> </strong>function from <code>ckeditor</code> providing <code>my-ckeditor</code> as DOM element&#8217;s id. However, it turns out that we cannot do it directly in the function component before returning, because our <strong>div</strong> is not loaded into the DOM yet at this moment.</p>



<p>Fortunately, there&#8217;s another, easy solution ?</p>



<h2 class="wp-block-heading">React on DOM element being mounted with <strong><em>useCallback</em></strong></h2>



<p>What we basically want to achieve is to execute the<strong> </strong><code>create</code> static function provided by <code>ckeditor</code> when our <code>div</code> is mounted into the DOM.</p>



<p>Let&#8217;s first install the ckeditor5 classic editor <a href="https://www.npmjs.com/package/@ckeditor/ckeditor5-build-classic" target="_blank" rel="noreferrer noopener">npm package</a>:</p>



<pre class="wp-block-code"><code>npm i @ckeditor/ckeditor5-build-classic</code></pre>



<p>Then require <code>ckeditor.js</code> file as <code>Ckeditor</code> in the<strong> .tsx </strong>file with our component:</p>



<pre class="wp-block-code"><code>const Ckeditor = require('@ckeditor/ckeditor5-build-classic/build/ckeditor.js');</code></pre>



<p>Now, instead of assigning an <code>id</code> to our <code>div</code> element, let&#8217;s use the <code>React.useCallback</code> hook and assign it to <code>div</code>&#8216;s <code>ref</code>:</p>



<script src="https://gist.github.com/dsibinski/f22f2ad36d1b108850a42eee81effd0a.js"></script>



<p>Our callback function will be called after our <code>div</code> component mounts (or unmounts). That&#8217;s why we check whether the <code>node</code> is defined, and then we can do something with that.</p>



<p>This is how it looks in debug mode:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="804" height="256" src="https://blog.yumasoft.pl/wp-content/uploads/2021/06/JS_component_in_React_final_result.png" alt="" class="wp-image-268" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/06/JS_component_in_React_final_result.png 804w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/JS_component_in_React_final_result-300x96.png 300w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/JS_component_in_React_final_result-768x245.png 768w" sizes="auto, (max-width: 804px) 100vw, 804px" /></figure>



<p>As you can see, <code>node</code> is defined, and it&#8217;s a <code>div</code>. Exactly the DOM element in which we want to render our <code>ckeditor</code> component. Let&#8217;s now simply change <code>console.log</code> to rendering the editor as per documentation:</p>



<script src="https://gist.github.com/dsibinski/fa08cd11f4974ba9b2d1a65461211bbb.js"></script>



<p>Thanks to that, we can see our editor rendered on the page:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="981" height="348" src="https://blog.yumasoft.pl/wp-content/uploads/2021/06/Ckeditor_rendered_on_React_page.png" alt="" class="wp-image-273" srcset="https://blog.yumasoft.pl/wp-content/uploads/2021/06/Ckeditor_rendered_on_React_page.png 981w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/Ckeditor_rendered_on_React_page-300x106.png 300w, https://blog.yumasoft.pl/wp-content/uploads/2021/06/Ckeditor_rendered_on_React_page-768x272.png 768w" sizes="auto, (max-width: 981px) 100vw, 981px" /></figure>



<h2 class="wp-block-heading">Summary</h2>



<p>We often use external components in our projects at Yumasoft. In case of above-mentioned <code>ckeditor</code>, we couldn&#8217;t use <a href="https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/frameworks/react.html" target="_blank" rel="noreferrer noopener">its React component</a> (because of various reasons) and we had to render it statically using JS function. The solution with <code>useCallback</code> turned out to be very useful here. I hope you also find it helpful one day if you ever need to use Javascript component in React ?</p>
<p>The post <a rel="nofollow" href="https://blog.yumasoft.pl/2021/06/how-to-use-javascript-component-in-react-component/">How to Use JavaScript Component in React Component</a> appeared first on <a rel="nofollow" href="https://blog.yumasoft.pl">Yumasoft</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.yumasoft.pl/2021/06/how-to-use-javascript-component-in-react-component/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
