<?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 Marcel Mokos on Medium]]></title>
        <description><![CDATA[Stories by Marcel Mokos on Medium]]></description>
        <link>https://medium.com/@marcelmokos?source=rss-4b9acead2b8f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0NgzEi9H3R0Fg_jw1Mmr4g.png</url>
            <title>Stories by Marcel Mokos on Medium</title>
            <link>https://medium.com/@marcelmokos?source=rss-4b9acead2b8f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 31 May 2026 20:34:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marcelmokos/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[Generate tests using AI, and learn from it!]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/ableneo/what-you-need-to-do-when-you-want-to-generate-tests-using-ai-cc290c10ccf6?source=rss-4b9acead2b8f------2"><img src="https://cdn-images-1.medium.com/max/2600/0*Q7qIP6NR7W5a70XE.jpg" width="2600"></a></p><p class="medium-feed-snippet">Developers frequently complain &#x201C;tests take too much time&#x201D; or &#x201C;testing is complicated. I do not know where to start.&#x201D; Do not worry, AI is&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/ableneo/what-you-need-to-do-when-you-want-to-generate-tests-using-ai-cc290c10ccf6?source=rss-4b9acead2b8f------2">Continue reading on ableneo tech &amp; transformation »</a></p></div>]]></description>
            <link>https://medium.com/ableneo/what-you-need-to-do-when-you-want-to-generate-tests-using-ai-cc290c10ccf6?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc290c10ccf6</guid>
            <category><![CDATA[ai-generated-test]]></category>
            <category><![CDATA[programming-principles]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[testing-with-ai]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Fri, 10 Mar 2023 09:23:52 GMT</pubDate>
            <atom:updated>2023-03-15T14:15:19.822Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to do state management in a modern React application with hooks and Context API]]></title>
            <link>https://medium.com/ableneo/how-to-do-state-management-in-a-modern-react-application-with-hooks-and-context-api-1fee3e5a3feb?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fee3e5a3feb</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react-context]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[context-api]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Mon, 21 Nov 2022 08:43:01 GMT</pubDate>
            <atom:updated>2022-11-30T07:52:41.638Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why you may not need global state management as much as you think</h3><h4>How to minimalize state management in a modern React application with libraries, hooks, and Context API</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MzlJy9IUTj8lWVv9" /><figcaption>Photo by <a href="https://unsplash.com/@noahbuscher?utm_source=medium&amp;utm_medium=referral">Noah Buscher</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Following this guide, you will reevaluate the introduction of the global state management library in your application. <strong>Most of the state can be delegated to specialized libraries,</strong> and the <strong>rest will be negligible</strong> to introduce a global state management library.</p><p>The reactJS ecosystem is very active and full of ideas and libraries. There are many opinions on state management, there is no right or wrong. Some developer groups are too convinced that the chosen library or approach is the ultimate solution. Overusing libraries to solve problems that were not meant to solve is common practice.</p><p>This article will explain the concepts and provide a guide for problems you may face. There is not right or wrong approach. Your application may have specific requirements, and choosing your library mix may be influenced by them.</p><h3>📀 What is the application state in React application?</h3><p>Anything that can be changed during the application run and the application should <strong>react</strong> to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/0*v4wicmbyK3hlTTZg.jpg" /><figcaption>meme, React application without a state is a static HTML website with extra steps</figcaption></figure><p>On every state change, the view would react to the given change by rendering an updated view.</p><h3>✍️ What does setState do?</h3><p>setState() schedules an update to a component’s state object. When the state changes, the component responds by re-rendering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*5Yp5bNLyMBYP5zyi.jpg" /><figcaption>meme, State changes are requests to perform re-rendering</figcaption></figure><h4>♻️ Reasons for the component to re-render</h4><ol><li><strong>Update in State</strong></li><li><strong>Re-rendering of the parent component</strong> only for children without<strong> </strong>memoization techniques (React.memo, useMemo)</li><li>Update in prop of the component with memoization techniques (React.memo, useMemo)</li><li>Context changes — if a component uses context consumer, it will be re-rendered every time the context provider’s value is changed.</li><li>Hooks changes — if a state or context provider’s value is changed in the hook or nested hook (regardless of whether this state is returned in the hook value and memoized or not)</li></ol><blockquote>If you want to read more about react re-rendering follow this article <a href="https://www.developerway.com/posts/react-re-renders-guide">https://www.developerway.com/posts/react-re-renders-guide</a></blockquote><h3>🎬 What actions are a common trigger to a state change?</h3><ul><li><strong>User input</strong> — text provided in the input, other events by keyboard or mouse interactions</li><li><strong>State from the server</strong> — the state change can be triggered when a request to a server is resolved or rejected</li><li><strong>Environment context </strong>—listening to user environment events, when the URL changes, online status, size of the device screen, orientation, and many more</li></ul><h3>🧑‍💻 Why do you want to use state management?</h3><p>State management is solving the problem of accessing and setting the application’s state. It may also provide a set of rules that make reasoning about the application data flow clear and predictable.</p><p>The other benefit is development experience many libraries include dev tools in the form of browser extensions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/0*ct1YvMU6tm8J5oK7.jpeg" /><figcaption>meme, Say React state management, one more time</figcaption></figure><h3>Popularization of Redux</h3><p>Since previous versions of <strong>React</strong> did not have public API for context and people were unfamiliar with Javascript development, the rules of the <strong>flax pattern</strong> were welcome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HjVNsEIF-OdK9Fbv.png" /><figcaption>A unidirectional data flow is central to the Flux pattern, and the above diagram should be the primary mental model for the Flux programmer. (source: <a href="https://facebook.github.io/flux/docs/in-depth-overview/">https://facebook.github.io/flux/docs/in-depth-overview/</a>)</figcaption></figure><blockquote>I am not mentioning other alternatives such as <a href="https://mobx.js.org/">MobX</a> that was popular at the time before hooks and public context API</blockquote><h4>Reason for the decline of Redux popularity</h4><p>Redux was overused when providing the same state to sibling components was impossible with React it was the first proposed way to solve this problem in tutorials.</p><ul><li>React made context API public</li><li>A lot of boilerplate code</li></ul><h4>Common miss use of Redux</h4><p>Since Redux was one of the first things, people switching to React were learning. It becomes a way to interact with Router State, Handle Request logic, and do not forget forms with <a href="https://redux-form.com/8.3.0/docs/gettingstarted.md/">Redux Form</a>. Using redux for everything has some benefits, like you had every action in one tool and debugger.</p><ul><li>using redux was making the whole app and sometimes simple components dependent on the redux. Tests had to mock redux</li><li>redux code was too specific, and it is hard to structure code in redux to encourage sharing features between project</li><li>redux uses performance optimizations but comparing, and recreating large state objects are costly in Javascript. Some wanted to solve this by immutable data structures, but performance benefits do not always exceed the costs and added complexity</li></ul><p><strong>Overusing libraries connected to the Redux state</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*7twZ5-DgrVIv2uCJ.jpg" /><figcaption>meme, Everybody Everywhere, Redux</figcaption></figure><ul><li><strong>router state</strong> can be managed by <a href="https://reacttraining.com/react-router/">React Router</a> and query parameters with <a href="https://www.npmjs.com/package/use-query-params">use-query-params</a> without <a href="https://github.com/supasate/connected-react-router">connecting router to redux</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*-obwVhM-PDGVi7uU.jpg" /><figcaption>meme, React, Redux, React Router. What’s next? Connect React Router to Redux. The meme was more fun when it said REACT-ROUTER-REDUX (now deprecated).</figcaption></figure><ul><li><strong>🚨 managing request state in redux</strong> seems like boilerplate overkill, but recently, you can use <a href="https://redux-toolkit.js.org/api/createAsyncThunk">createAsyncThunk</a> from <a href="https://redux-toolkit.js.org/">Redux Toolkit</a> to reduce boilerplate. You will not have any of the features of a <a href="https://react-query-v3.tanstack.com/">React Query</a>, <a href="https://swr.vercel.app/">SWR</a>, or other libraries out of the box, like resolving requests from cache, auto-reload, on-tab focus, or many others.</li></ul><blockquote>There is another tool by <a href="https://redux-toolkit.js.org/">Redux Toolkit</a> team <a href="https://redux-toolkit.js.org/rtk-query/overview">RTK Query</a> that provides features of <a href="https://react-query-v3.tanstack.com/">React Query</a> or other libraries. <a href="https://redux-toolkit.js.org/rtk-query/comparison#when-should-you-use-rtk-query">See the comparision</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*coEedRYw7TmHgwVR.jpg" /><figcaption>meme, setState, Redux, Custom redux action creators and middleware, Redux Toolkit, createAsyncThunk, RTK-Query, React Query</figcaption></figure><ul><li><strong>form state</strong> stored in <a href="https://redux-form.com/8.3.0/docs/gettingstarted.md/">Redux Form</a> was causing unnecessary rerenders on every input in the form. Libraries such as <a href="https://formik.org/">Formik</a> improved and later introduced a more performant <a href="https://react-hook-form.com/">React Hook Form</a>, reduced the rerenders, and made large dynamic forms not problematic again.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/0*XP9ZHxYAp1KbFDGm.jpg" /><figcaption>meme, Here we see react engineer deploying a contact form</figcaption></figure><h4>What is good about Redux</h4><ul><li><strong>flux pattern</strong> with <strong>actions</strong> and <strong>reducers</strong></li><li>optimized subscription to the state using state selectors</li><li><strong>documentation</strong> and ecosystem</li><li><strong>debugger</strong> browser extension <strong>with time traveling</strong>, and inspections</li></ul><p>You should consider your project needs and redux, in some cases, solves project needs more than alternatives</p><h3>Recoil as alternative state management to Redux</h3><p>Use <a href="https://recoiljs.org/">Recoil</a> when you have rapidly changing UI, deeply nested data structures, and performance is important.</p><p>Support using complex data structures (trees, graphs, you name it). Each piece of shared state is called an atom, and atoms can be combined with selectors that only recompute whenever an atom changes. Asynchronicity is built in.</p><p>The documentation is great, and the API is starting to become stable. If you require a performant shared state in your application, this is a great tool to reach for.</p><h3>React with hooks and Context API</h3><p>Context can provide value to children components when a child component consumes the context, it will subscribe to changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*4_0dXTLw5o3CPJRo.jpg" /><figcaption>Redux =&gt; React Context API</figcaption></figure><h4>🚀 Advantages</h4><ul><li>provided by React works out of the box</li><li>hooks encourage <strong>composition</strong> and <strong>reusability</strong></li><li>hooks can remove logic from component render functions</li><li>hooks and context is easy to test when you extract the business logic into separate functions</li><li>context does not have to cover the whole application, (theming, UI, and animation states)</li><li>use hooks from the npm repository. No duplication or synchronization</li></ul><h4>🚨 Disadvantages</h4><ul><li>performance implications, if not used properly with memoization</li></ul><h4>💡 Leave specialized tasks to specialized npm modules</h4><ul><li>If the user can share the URL with query parameters that influence render, then store the state in <a href="https://reacttraining.com/react-router/">React Router</a> and query parameters with <a href="https://www.npmjs.com/package/use-query-params">use-query-params</a></li><li>fetch, cache, and updating data should be outsourced to a well-documented maintained external library without touching any “global state”. (<a href="https://react-query-v3.tanstack.com/">React Query</a>, <a href="https://swr.vercel.app/">SWR</a>)</li><li>leave handling forms to the external library with performant, flexible API, and mutate server data only when the form is submitted. (<a href="https://react-hook-form.com/">React Hook Form</a>)</li></ul><h4>What state we will manage in the application?</h4><p>When we follow these recommendations. <strong>The state will be negligible to introduce a global state management library.</strong></p><h3>Example</h3><p>Initialize <strong>react-query</strong></p><pre>import { QueryClient, QueryClientProvider } from &quot;react-query&quot;;<br><br>// Create a client<br>const queryClient = new QueryClient();<br><br>export default () =&gt; {<br>  return (<br>    // Provide the client to your App<br>    &lt;QueryClientProvider client={queryClient}&gt;<br>      &lt;Page /&gt; /* Or &lt;Routers /&gt;*/<br>    &lt;/QueryClientProvider&gt;<br>  );<br>}</pre><p>Create <em>src/api/userApi.ts (for this case, the axios request is mocked).</em></p><pre>import axios from &quot;axios&quot;;<br>import MockAdapter from &quot;axios-mock-adapter&quot;;<br><br>const mock = new MockAdapter(axios);<br><br>export enum Role {<br>  admin = &quot;admin&quot;,<br>  user = &quot;user&quot;,<br>}<br><br>mock.onGet(&quot;/user&quot;).reply((config) =&gt; [<br>  200,<br>  {<br>    user: {<br>      userId: config.params.userId ?? 1,<br>      name: &quot;John Smith&quot;,<br>      role: Role.admin,<br>    },<br>  },<br>]);<br><br>export type User = {userId: number; name: string; role: Role};<br><br>export const userApi = {<br>  getUser: ({userId}: {userId?: number} = {}) =&gt;<br>    axios.get&lt;{user: User}&gt;(&quot;/user&quot;, {params: {userId}}),<br>};</pre><p>Use <strong>react-query </strong>for request</p><pre>import { UserProperties } from &quot;../components/UserProperties&quot;;<br>import { AxiosError } from &quot;axios&quot;;<br>import { useQuery } from &quot;react-query&quot;;<br>import { userApi } from &quot;../api/userApi&quot;;<br><br>export const UserDetail = ({id = 2}) =&gt; {<br>  const query = useQuery(`user-${id}`, () =&gt; userApi.getUser({ id }));<br><br>  if (query.isLoading) {<br>    return &lt;p&gt;Loading...&lt;/p&gt;;<br>  }<br><br>  const user = query?.data?.data?.user;<br><br>  if (query.isError) {<br>    return (<br>      &lt;p&gt;<br>        Error loading user:{&quot; &quot;}<br>        {(query?.error as AxiosError)?.message ?? &quot;unknown error&quot;}<br>      &lt;/p&gt;<br>    );<br>  }<br><br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;User detail&lt;/h1&gt;<br><br>      {user &amp;&amp; &lt;UserProperties {...user} /&gt;}<br>    &lt;/&gt;<br>  );<br>};</pre><p>Refactor to separate hook (query key creation encapsulated, query key is used as cache key)</p><pre>import { useQuery } from &quot;react-query&quot;;<br>import { userApi } from &quot;../api/userApi&quot;;<br><br>export const useUserQuery = ({ userId }: { userId?: number } = {}) =&gt; {<br>  return useQuery(`user-${userId}`, () =&gt; userApi.getUser({ userId }));<br>};</pre><p><strong>useUserQuery</strong> hook usage, you can provide hooks as props or use default props</p><pre>import {UserProperties} from &quot;../components/UserProperties&quot;;<br>import {AxiosError} from &quot;axios&quot;;<br>import {useUserQuery} from &quot;../hooks/useUserQuery&quot;;<br><br>const defaultProps = {<br>  userId: 2,<br>  useUserQueryHook: useUserQuery,<br>};<br><br>export const UserDetail = ({userId, useUserQueryHook}: typeof defaultProps) =&gt; {<br>  const query = useUserQueryHook({userId});<br><br>  if (query.isLoading) {<br>    return &lt;p&gt;Loading...&lt;/p&gt;;<br>  }<br><br>  if (query.isError) {<br>    return (<br>      &lt;p&gt;<br>        Error loading user:{&quot; &quot;}<br>        {(query?.error as AxiosError)?.message ?? &quot;unknown error&quot;}<br>      &lt;/p&gt;<br>    );<br>  }<br><br>  const user = query?.data?.data?.user;<br><br>  return &lt;&gt;{user &amp;&amp; &lt;UserProperties {...user} /&gt;}&lt;/&gt;;<br>};<br><br>UserDetail.defaultProps = defaultProps;</pre><h4>Code sandbox interactive example</h4><p>Look at the option to provide a hook as a prop to the component.</p><p>Usage of context to <em>&lt;CurrentUserRole /&gt; </em>and implementation of <em>useCurrentUserQuery</em> hook.</p><pre>import {UserDetail} from &quot;../containers/UserDetail&quot;;<br>import {CurrentUserRole} from &quot;../components/CurrentUserRole&quot;;<br>import {useCurrentUserQuery} from &quot;../hooks/useCurrentUserQuery&quot;;<br><br>export const Page = () =&gt; (<br>  &lt;&gt;<br>    &lt;CurrentUserRole /&gt;<br>    &lt;h1&gt;Current User detail&lt;/h1&gt;<br>    &lt;UserDetail useUserQueryHook={useCurrentUserQuery} /&gt;<br>    &lt;h1&gt;User detail&lt;/h1&gt;<br>    &lt;UserDetail /&gt;<br>  &lt;/&gt;<br>);</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ffocused-bird-10w9c5%3Fautoresize%3D1%26fontsize%3D14%26hidenavigation%3D1%26module%3D%252Fsrc%252Fpages%252FPage.tsx%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fmh5o3b&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F10w9c5%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/41358ceb4618260cfa590fd5914ffc3a/href">https://medium.com/media/41358ceb4618260cfa590fd5914ffc3a/href</a></iframe><p>👏Clap, 👂follow for more awesome 💟#Javascript and ⚛️#React content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fee3e5a3feb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ableneo/how-to-do-state-management-in-a-modern-react-application-with-hooks-and-context-api-1fee3e5a3feb">How to do state management in a modern React application with hooks and Context API</a> was originally published in <a href="https://medium.com/ableneo">ableneo tech &amp; transformation</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Typing of React hooks in Typescript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/ableneo/typing-of-react-hooks-in-typescript-947b200fa0b0?source=rss-4b9acead2b8f------2"><img src="https://cdn-images-1.medium.com/max/1200/1*xq6YbMEB1iNpUsOH52yucg.jpeg" width="1200"></a></p><p class="medium-feed-snippet">Hooks are now the better option to do effects in react. Using hooks with typescript can be complicated at first let&#x2019;s dive in.</p><p class="medium-feed-link"><a href="https://medium.com/ableneo/typing-of-react-hooks-in-typescript-947b200fa0b0?source=rss-4b9acead2b8f------2">Continue reading on ableneo tech &amp; transformation »</a></p></div>]]></description>
            <link>https://medium.com/ableneo/typing-of-react-hooks-in-typescript-947b200fa0b0?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/947b200fa0b0</guid>
            <category><![CDATA[setstate]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[typescript-with-react]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Thu, 21 May 2020 16:00:19 GMT</pubDate>
            <atom:updated>2022-07-04T05:21:56.361Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Javascript debugging in IntelliJ IDEA]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/ableneo/javascript-debugging-in-intellij-idea-997287f15e91?source=rss-4b9acead2b8f------2"><img src="https://cdn-images-1.medium.com/max/1629/1*V2B26U2piEs48tSaGynSmA.jpeg" width="1629"></a></p><p class="medium-feed-snippet">Developing amazing user interfaces does not come without obstacles let&#x2019;s learn how to investigate and to resolve them with ease.</p><p class="medium-feed-link"><a href="https://medium.com/ableneo/javascript-debugging-in-intellij-idea-997287f15e91?source=rss-4b9acead2b8f------2">Continue reading on ableneo tech &amp; transformation »</a></p></div>]]></description>
            <link>https://medium.com/ableneo/javascript-debugging-in-intellij-idea-997287f15e91?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/997287f15e91</guid>
            <category><![CDATA[intellij]]></category>
            <category><![CDATA[debugging-javascript]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[debugger]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Fri, 27 Mar 2020 09:52:25 GMT</pubDate>
            <atom:updated>2020-04-17T10:00:08.163Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[React setState does not immediately update the state]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/ableneo/react-setstate-does-not-immediately-update-the-state-84dbd26f67d5?source=rss-4b9acead2b8f------2"><img src="https://cdn-images-1.medium.com/max/1200/1*HH6v6UQMsYX5DVcFByDqQw.jpeg" width="1200"></a></p><p class="medium-feed-snippet">React hooks are now preferred for state management. Calling setState multiple times in one function can lead to unpredicted behavior read&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/ableneo/react-setstate-does-not-immediately-update-the-state-84dbd26f67d5?source=rss-4b9acead2b8f------2">Continue reading on ableneo tech &amp; transformation »</a></p></div>]]></description>
            <link>https://medium.com/ableneo/react-setstate-does-not-immediately-update-the-state-84dbd26f67d5?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/84dbd26f67d5</guid>
            <category><![CDATA[setstate]]></category>
            <category><![CDATA[async]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Fri, 27 Mar 2020 09:24:28 GMT</pubDate>
            <atom:updated>2022-05-19T08:21:34.457Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Master React with Typescript and Unit Tests]]></title>
            <link>https://medium.com/ableneo/master-react-with-typescript-and-unit-tests-9cd4166214fa?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cd4166214fa</guid>
            <category><![CDATA[strong-typing]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Thu, 17 Oct 2019 10:56:48 GMT</pubDate>
            <atom:updated>2019-10-17T12:07:02.339Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Yjg4EAiJbmE88O3J" /><figcaption>Photo by <a href="https://unsplash.com/@fredmarriage?utm_source=medium&amp;utm_medium=referral">freddie marriage</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Most of the React components in our projects should be simple, reusable, testable and well-typed. Design components with well-defined properties that are easy to read and understand.</p><p>Enhance your developer productivity and experience. Use and promote relevant React abstractions and patterns formulated with the type-safety of Typescript. Types will help us avoid obvious problems in code. Tests for logic in the code are better than repetitive visual debugging.</p><h3>Reason for type checking</h3><p>The purpose of programming is to find a sequence of instructions that will automate the performance of a task for solving a given problem. Tasks are often created in distributed teams that need to communicate. Task inputs and outputs need to be well-documented contracts.</p><p>The ultimate goal is to make code easy to read, understand and validate. Distributed teams need strict static verification of the code. Types let you define interfaces between software components and gain insights into the behavior of existing JavaScript libraries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/0*ENLh50zu_NjIVr24" /><figcaption>Why Use types. (image source: <a href="https://codeburst.io/strict-types-typescript-flow-javascript-to-be-or-not-to-be-959d2d20c007">link</a>)</figcaption></figure><h4>Advantages of types</h4><ul><li>improves code readability</li><li>provide valuable information about the code</li><li>better code analysis</li><li>static verification</li><li>early detection of errors</li><li>code autocomplete</li><li>robust dependable refactoring</li></ul><h3>JSDoc</h3><blockquote><strong>JSDoc</strong> is a <a href="https://en.wikipedia.org/wiki/Markup_language">markup language</a> used to annotate <a href="https://en.wikipedia.org/wiki/JavaScript">JavaScript</a> <a href="https://en.wikipedia.org/wiki/Source_code">source code</a> files. <a href="https://github.com/jsdoc/jsdoc">Docs</a> and <a href="https://devhints.io/jsdoc">cheatsheet</a>.</blockquote><p>Documenting types in Javascript using JSDoc comments is still valuable option. Editors, compilers and type checkers can read this information and provide you with error message hints.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d86f0bf79556a71b26969ef69450951/href">https://medium.com/media/3d86f0bf79556a71b26969ef69450951/href</a></iframe><h4>Advantages</h4><ul><li>editor tooling, autocomplete</li><li>comment based</li><li>could be used to generate documentation</li><li>can be read by other type checkers (<a href="https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html">TypeScript checks JSDoc annotations</a>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*DDhD2vuKatA_GVCM.jpg" /><figcaption><a href="https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html">TypeScript can check plan Javascript and JSDoc annotations</a></figcaption></figure><h4>Disadvantages</h4><ul><li>not a full-featured language</li><li>typing function arguments and return types not guaranteed</li></ul><blockquote>JSDoc is useful for comment styling and tags like @deprecated that marks a method as deprecated in the project.</blockquote><h3>Type checking With React PropTypes</h3><p><a href="https://reactjs.org/docs/typechecking-with-proptypes.html">read docs</a> now in separate package <a href="https://www.npmjs.com/package/prop-types">prop-types</a>. When an invalid value is provided for a prop, a warning will be shown during the run time in the JavaScript console.</p><h4>Optional props</h4><p>You can declare that a prop is a specific Javascript primitive. <br>By default, these are all optional.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3e7dd6ad3c5a5296536d85b2ec173b8/href">https://medium.com/media/c3e7dd6ad3c5a5296536d85b2ec173b8/href</a></iframe><p>Example with defaultProps and optional name of type string. Use optional properties only if the property has value in default props.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fhidden-sound-k45oi%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fhidden-sound-k45oi%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fk45oi%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb2e30502b61f295fb12c64829bc6471/href">https://medium.com/media/eb2e30502b61f295fb12c64829bc6471/href</a></iframe><h4>Required props</h4><p>The warning is shown if the prop isn’t provided.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ab5544463cbeb7715ba02201ac9dd00/href">https://medium.com/media/4ab5544463cbeb7715ba02201ac9dd00/href</a></iframe><h4>Advantages</h4><ul><li>small standalone library focused on React components</li><li>can be removed in the production build</li></ul><h4>Disadvantages</h4><ul><li>missing typing for <strong>function arguments and return types</strong></li><li>not practical outside React</li><li>you have to run the code to see the errors*</li><li><em>some editors will show errors/hints during development.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*PAWHvT_vD84b8QyL.jpeg" /><figcaption>Why would you NOT use TypeScript?</figcaption></figure><h3>Typescript</h3><p>The same syntax as JavaScript with the benefit of optional types. Able to fully type <strong>functional arguments and return types.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*M3kLjt386s6GvYNg.png" /><figcaption>Mr. Typed Data</figcaption></figure><h4><strong>basic types</strong></h4><p>TypeScript supports much the same types as you would expect in JavaScript.</p><p>If you want to refresh what you know about Javascript data types, please read the following article from my Javascript course.</p><p><a href="https://medium.com/ableneo/javascript-course-language-basics-variables-data-types-ee2874763180">Javascript course — Language basics, variables, data types</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/150a740a727da104983ca1ccf2e262be/href">https://medium.com/media/150a740a727da104983ca1ccf2e262be/href</a></iframe><h4>utility types</h4><p>TypeScript provides several utility types to facilitate common type transformations. These utilities are available globally.</p><ul><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#partialt">Partial&lt;T&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlyt"><strong>Readonly&lt;T&gt;</strong></a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkt">Record&lt;K,T&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#picktk">Pick&lt;T,K&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#omittk">Omit&lt;T,K&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#excludetu">Exclude&lt;T,U&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#extracttu">Extract&lt;T,U&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullablet">NonNullable&lt;T&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypet">ReturnType&lt;T&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#instancetypet">InstanceType&lt;T&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredt">Required&lt;T&gt;</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#thistypet">ThisType&lt;T&gt;</a></li></ul><h4>functions</h4><p>Functions are the fundamental building block of any application in JavaScript.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e99139097255c9a727b5ffa18796eda0/href">https://medium.com/media/e99139097255c9a727b5ffa18796eda0/href</a></iframe><h4>functions with an object argument</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e76cb5b5c301a26e4034e46cb2aff8e/href">https://medium.com/media/0e76cb5b5c301a26e4034e46cb2aff8e/href</a></iframe><p><strong>The problem when the function takes more parameters</strong></p><blockquote>The function should have a maximum of <strong>one required</strong> and <strong>one optional</strong> parameter. Most of the time use object as a parameter/argument.</blockquote><p><a href="https://medium.com/ableneo/javascript-course-javascript-the-good-parts-frequently-used-in-react-f873e79b98bc">Javascript course — Javascript the good parts frequently used in React</a></p><h4>interface</h4><p>The interface is a promise or a contract to <strong>implement</strong> a data shape. An interface can be extended. Interfaces with the same name are merged.</p><pre>interface Point2D {<br>  x: number;<br>  y: number<br>}</pre><pre>interface Point3D extends Point2D {<br>  z: number;<br>}</pre><h4>type</h4><p>The type is a definition of a type of data that can be <strong>declared</strong> and assigned. It allows the creating of a new name for a primitive type.</p><pre>type Coordinate = number;</pre><pre>type Point2D = {<br>  x: Coordinate;<br>  y: Coordinate; <br>};</pre><pre>type Point3D = Point2D &amp; {z: Coordinate};</pre><h4>typeof</h4><p>In some cases is useful to just create type based on an existing object.</p><pre>const defaultProps = {greeting: &quot;Hello&quot;};</pre><pre>type Props = Readonly&lt;typeof defaultProps &amp; {name: string}&gt;;</pre><pre>// type Props = {readonly name: string; readonly greeting: string}</pre><h4>Advantages</h4><ul><li>language as a superset of Javascript</li><li>all the advantages of strong typing</li><li>can inference types</li><li>can read Javascript files, JSDoc comments</li><li>advanced types, generics, utility types</li><li>have strong community and large library of types for third party libraries</li></ul><h4>Disadvantages</h4><ul><li>can get complicated to type functions with generic types or components as arguments</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Jyc5b5cJ56EyOI-A.jpg" /><figcaption>No runtime checks</figcaption></figure><h3>Before start using types some best practices</h3><p><a href="https://medium.com/ableneo/best-practices-for-javascript-projects-4b0dd7aaf810">Best practices for Javascript projects</a></p><h3>Assignment</h3><p>Create a box similar to the one that Facebook uses for sharing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*swk7Bf7dAs7pOXhYCObKQQ.png" /><figcaption>FB share box</figcaption></figure><p>There is a codesandbox ready for you where you have fake data and examples of components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5f18c095fbdcaa3133c758c6dee15cc/href">https://medium.com/media/f5f18c095fbdcaa3133c758c6dee15cc/href</a></iframe><h4>Codesandbox</h4><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fthirsty-http-9qvwc%3Ffontsize%3D14&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fthirsty-http-9qvwc%3Ffontsize%3D14&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec32d2f55b0e8e38f5c90a49b747c51a/href">https://medium.com/media/ec32d2f55b0e8e38f5c90a49b747c51a/href</a></iframe><h4>Tasks</h4><ul><li>change the component to look like Facebook post</li><li>convert getBlog into separate hook useGetBlog</li></ul><h4>Result</h4><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fmaster-react-with-typescript-and-unittests-ukbth&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fmaster-react-with-typescript-and-unittests-ukbth&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f6d6f8de118c161cd90fad467b660ee/href">https://medium.com/media/2f6d6f8de118c161cd90fad467b660ee/href</a></iframe><p>👏Clap, 👂follow for more awesome 💟#Javascript and ⚛️#automatization content.</p><p>Please provide feedback here <a href="https://forms.gle/V7w6CUcmzP8WWU1F8">link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cd4166214fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ableneo/master-react-with-typescript-and-unit-tests-9cd4166214fa">Master React with Typescript and Unit Tests</a> was originally published in <a href="https://medium.com/ableneo">ableneo tech &amp; transformation</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best practices for Javascript projects]]></title>
            <link>https://medium.com/ableneo/best-practices-for-javascript-projects-4b0dd7aaf810?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b0dd7aaf810</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Wed, 25 Sep 2019 05:01:02 GMT</pubDate>
            <atom:updated>2021-08-12T20:21:22.755Z</atom:updated>
            <content:encoded><![CDATA[<p>Planning with development strategy is lowering the probability of delays or project failures. Examine some of the best practices that can help you deliver solid code with reduced effort and maintenance costs.</p><h3>Know the language</h3><p>The latest Javascript specification introduced useful syntax. It is recommended to use the default syntax over the previous unpure methods. Today you do not need <a href="https://lodash.com/">Lodash</a>, <a href="https://underscorejs.org/">Underscore</a> or <a href="https://ramdajs.com/">Ramda</a> most of the time.</p><ul><li>Prefer JavaScript documentation on <a href="https://developer.mozilla.org">MDN (Mozilla developer network)</a> over other sources</li></ul><h4>Full Javascript course with examples, tips, and best practices</h4><p><a href="https://medium.com/ableneo/what-is-javascript-51b8e9623e11">Javascript course — What is Javascript, where can I use it?</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZeUi_-aKSVXwIGIUyItYZg.png" /><figcaption>const, let | array methods map, filter, reduce | object spread, rest operator, destructuring</figcaption></figure><p><strong>const</strong>, exceptionally <strong>let </strong>variable declaration</p><ul><li>Will not pollute the upper or global scope, and const is signaling that the value will never change.</li></ul><p><strong>map</strong>, <strong>filter</strong>, <strong>reduce </strong>array methods</p><ul><li>Do not need intermediate variables, can be chained.</li></ul><p>Object and array <strong>destructuring</strong>, renaming variables<strong> </strong>and<strong> default values</strong></p><ul><li>Makes functions with an object as an argument simple and useful</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TEtvnzrEe29b73wxQSEiAA.png" /><figcaption>arrow function, async-await, generators</figcaption></figure><h4>Arrow functions — expression is a syntactically compact alternative to a regular <strong>function</strong> expression</h4><ul><li>const fn = () =&gt; {}; will prevent function name collisions</li><li>An arrow function does not have its own this</li></ul><blockquote>Arrow functions are alternatively called lambda expressions.</blockquote><h4><strong>Async function — the </strong>declaration defines an <strong>asynchronous function</strong></h4><ul><li>async code is written in synchronous style no more then chaining, and creating and returning of promises</li></ul><pre>const fn = async () =&gt; { return setTimeout(() =&gt; 42), 1000};</pre><ul><li>the async keyword is automatically transforming the output of the function into a new Promise</li></ul><pre>const fn = () =&gt; { <br>  return new Promise((resolve) =&gt; { resolve(42); }, 1000)<br>};</pre><h3>Code newer lies comments and documentation sometimes do</h3><h4>Clear Intention without comments</h4><p>The code should be written like plain English communicating its intentions. The focus is to make code readable for the next customer your colleague developer.</p><h4>Meaningful variable names</h4><p>Correctly used variable names do not need comments and explanations that can get out of sync with the code rather quickly. The code is written and should be readable for humans.</p><blockquote>The code is read more often than it is written.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9DWvCCHB2rFb4eSOCJsOg.png" /><figcaption>do not use 🚨 <strong>data, val, str, x, y, z. </strong>use explicit variable names with the structure like <strong>valueInUnits</strong></figcaption></figure><pre>// 🚨 bad</pre><pre>const time = 60;</pre><pre>// 👍 good</pre><pre>const timeInMinutes = 60;</pre><pre>// 🚨 bad</pre><pre>const interest = 2.5;</pre><pre>// 👍 good</pre><pre>const yearlyInterestInPercents = 2.5;</pre><h4>Boolean values with the prefix “is” and “has”</h4><p>Using variables with prefixes is and has will communicate clearly that the variable is a Boolean. The code is read more often than it is written.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*neTDIh1jqu9luB9xBwASyA.png" /><figcaption>use prefix is, has for boolean values</figcaption></figure><h4>Prefer using named variables over comments</h4><p>Explain conditions with variable names rather than comments</p><pre>// 🚨 bad</pre><pre>if (height &gt; 100) {...}</pre><pre>// 👍 good</pre><pre>const minimutHeightInCm = 100;<br>const hasMinimumHeight = heightInCm &gt; minimutHeightInCm;<br>if (hasMinimumHeight) {...}</pre><p>Named variables can be reused and combined.</p><pre>const isPositiveNumber = x &gt; 0;<br>const isEvenNumber = x % 2;<br>const isOddNumber = !isEvenNumber;<br>const isPositiveEvenNumber = isPositive &amp;&amp; isEven;</pre><h3>Readability over questionable performance improvements</h3><h4>Prefer array methods</h4><p>It is recommended to use a functional approach without intermediate variables.</p><blockquote>The base Javascript <strong>for </strong>cycle can be more performant in some browsers but the benefit can be measured only by iterating over millions of items. It is job of compiler and runtime to remove penalty of using new array methods.</blockquote><pre>// 🚨 bad</pre><pre>let str = &quot;&quot;;</pre><pre>for (var i = 0; i &lt; 10; i++) {<br>  str = `${str}${i}`;<br>}</pre><pre>console.log(str);<br>// expected output: &quot;0123456789&quot;</pre><pre>// 👍 good</pre><pre>console.log(<br>  [...new Array(10).keys()].join(&quot;&quot;)<br>);<br>// expected output: &quot;0123456789&quot;</pre><pre>// 🚨 bad</pre><pre>let sum = 0;</pre><pre>for (var i = 0; i &lt; 10; i++) {<br>  sum = sum + i;<br>}</pre><pre>console.log(sum);<br>// expected output: 45</pre><pre>// 👍 good</pre><pre>console.log(<br>  [...new Array(10).keys()]<br>    .reduce((acc, key) =&gt; acc + key, 0)<br>);<br>// expected output: 45</pre><blockquote>We should ignore critics and switch to new syntax because it is shorter, more readable, and can be parallelized in the future.</blockquote><p><a href="https://codesandbox.io/s/trusting-mendel-p16mu?expanddevtools=1&amp;fontsize=14">trusting-mendel-p16mu - CodeSandbox</a></p><h4>The problem when the function takes more parameters</h4><p>The function should have a maximum of <strong>one required</strong> and <strong>one optional</strong> parameter. Most of the time use object as a parameter/argument.</p><p><a href="https://medium.com/ableneo/javascript-course-javascript-the-good-parts-frequently-used-in-react-f873e79b98bc">Javascript course — Javascript the good parts frequently used in React</a></p><p><strong>Creating and merging objects<br></strong>It is not free to create an object on every call of the function. But the benefit of readability of the object argument is more significant than some preemptive micro-optimization.</p><h3>Understand the benefits of testing</h3><p>Tests are saving development time, and maintenance cost.</p><p>When tests are required developers are motivated to write smaller testable functions. Testing simple pure functions do not demand to mock large parts of the app.</p><h4>Pure functions</h4><p>A pure function is a function where the return value is only determined by its input values, without observable side effects.</p><blockquote><em>Unit testing is better than debugging, whole app every time.</em></blockquote><p><a href="https://medium.com/ableneo/testable-javascript-functional-programming-pure-functions-756e049bfd4a">Testable Javascript -&gt; Functional Programming -&gt; Pure Functions</a></p><h4>Separation of concerns</h4><p>A Function should do one testable thing only. It is recommended to keep layers of the app separate from the other.</p><p>The function should inject constants and other functions using the object parameter with reasonable defaults that will open future overrides and ease testing.</p><blockquote>UI rendering function should not have access to whole state or state management. Inject only necessary parts of the state and provide only necessary action creators/functions.</blockquote><h4>Component groups separation to allow testing</h4><ul><li>following a few simple rules will promote reusability and testability of components</li></ul><ol><li><strong>Atoms</strong> simple component with styles</li><li><strong>Molecules</strong> groups of simple components with styles</li><li><strong>Organisms</strong> components with minimal details for rendering can call functions to handle specific events. Can have style adjustments for specific business use cases</li></ol><p>3*. Connector or state provider for <strong>Organisms </strong>provides or selects state for a component</p><p>4. <strong>Templates</strong> place components into a page layout that can be used in pages</p><p>5. <strong>Pages </strong>are specific instances of templates that show what a UI looks like with real representative content in place</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nfxHwtYxlR8sMSjN.png" /><figcaption>Component groups</figcaption></figure><h3>Static typing</h3><p>Confidence added by static typing will compensate for extended effort of writing types. Static typing with modern IDE is rapidly improving the developer experience with autocomplete and error highlighting.</p><blockquote>Types can unveil the entire class of bugs that even testing can not indicate.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJe_BHLGLG4iyFzivmWxwQ.png" /><figcaption>Static typing reveals bugs on every keypress</figcaption></figure><ul><li>Typescript is preferred by the library authors</li><li>Flow in some cases has some benefits for React projects</li></ul><h3>React and Typescript | Example</h3><ul><li>The goal is to create reusable components</li><li>A component can have other components in its default props</li><li>Default props used in render props pattern can be statically typed</li></ul><pre>type Props = {} &amp; typeof defaultProps;</pre><pre>type Children = (props: Props) =&gt; JSX.Element;</pre><pre>export const Header = <br>  ({children, ...props}: {children: Children} &amp; Props) =&gt;          <br>    children(props);</pre><ul><li>the default render function can be provided for styleguide</li></ul><pre>Header.defaultProps = {<br>  ...defaultProps,<br>  children: ({Wrapper, Group}: Props) =&gt; (<br>    &lt;Wrapper&gt;<br>      &lt;Group&gt;Left&lt;/Group&gt;<br>      &lt;Group&gt;Center&lt;/Group&gt;<br>      &lt;Group&gt;Right&lt;/Group&gt;<br>    &lt;/Wrapper&gt;<br>  ),<br>};</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Freact-project-typescript-render-props-e302f%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Freact-project-typescript-render-props-e302f%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fe302f%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/580a9f6b48bf36d83d9750249d5925f7/href">https://medium.com/media/580a9f6b48bf36d83d9750249d5925f7/href</a></iframe><h4>Component rendered with default children function</h4><blockquote><em>Header variant “space-between”</em></blockquote><pre>&lt;Header /&gt;</pre><h4>Override component using props</h4><blockquote><em>Header variant “space-around”</em></blockquote><pre>const App = ({CustomHeaderWrapper}) =&gt; (<br>  &lt;Header Wrapper={CustomHeaderWrapper} /&gt;<br>);</pre><pre>App.defaultProps = {<br>  CustomHeaderWrapper: styled(Header.defaultProps.Wrapper)`<br>     justify-content: space-around;<br>  `,<br>};</pre><h4>Override component using props and provide render function</h4><blockquote><em>Header variant replacing children</em></blockquote><pre>&lt;Header Wrapper={CustomHeaderWrapper}&gt;<br>  {({Wrapper, Group}) =&gt; (<br>    &lt;Wrapper&gt;<br>      &lt;Group&gt;Center&lt;/Group&gt;<br>    &lt;/Wrapper&gt;<br>  )}<br>&lt;/Header&gt;</pre><h4>Type safety when you use an undefined prop</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoId0TpJObGC6-vN_bM4-g.png" /><figcaption>Type Error for “Missing” property of the component</figcaption></figure><h3>Data management</h3><p><strong>selectors</strong> decouple shape of application state with shape of the component props</p><p><strong>normalization and denormalization </strong>treat the state of the application as a relational database.</p><ul><li>duplicities in application state produce bugs when updates do not address all the duplicities</li><li>loading and storing nested entities significantly enlarge rest payloads and processing</li><li>prefer the use projects like <a href="https://github.com/paularmstrong/normalizr">normalizr</a> and normalization of nested JSON according to a schema</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fpkvo57v750%3Ffontsize%3D14%26module%3D%252Fsrc%252Ffake.js%26moduleview%3D1&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fpkvo57v750%3Ffontsize%3D14%26module%3D%252Fsrc%252Ffake.js%26moduleview%3D1&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/81d420e4b588deb593ef3e3998dbea2b/href">https://medium.com/media/81d420e4b588deb593ef3e3998dbea2b/href</a></iframe><h3>Invest in tooling that can save time</h3><blockquote>An example can be found in <a href="https://github.com/ableneo/modules">https://github.com/ableneo/modules</a> and eslint config in the <a href="https://github.com/ableneo/modules/tree/master/packages/eslint-config-ableneo">eslint-config-ableneo</a>.<br><a href="https://github.com/ableneo/modules/tree/master/packages/eslint-config-ableneo#installation">Config installation guide.</a></blockquote><p><strong>precommit should</strong></p><ul><li>pretty print</li><li>lint the code, type checking</li><li>run all the tests related to changed files in git</li></ul><p><strong>prepush</strong></p><ul><li>lint the code, type checking</li><li>run all the unit test</li></ul><p><strong>CD/CI</strong></p><ul><li>try to merge</li><li>run prepush checks again</li><li>start build</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kxbBhPPhWNMzXnQtp9mXhw.png" /><figcaption>prettier, eslint, babel, typescript</figcaption></figure><h3>Code generators</h3><p>There are two good generator libraries <a href="https://plopjs.com/">plopjs</a> and <a href="https://www.hygen.io/">hygen</a>. A short <a href="https://www.hygen.io/">hygen</a> tutorial is available in an article with an example.</p><p><a href="https://medium.com/ableneo/how-to-use-the-hygen-code-generator-4bab25d99d8b">How to use the hygen code generator</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATAbM7oOHlasMfWBrJfYDQ.png" /></figure><blockquote>Another example of hygen is initializer <a href="https://github.com/ableneo/modules/tree/master/packages/hygen-eslint-config-ableneo">hygen-eslint-config-ableneo</a> for our <a href="https://github.com/ableneo/modules/tree/master/packages/eslint-config-ableneo">eslint-config-ableneo</a></blockquote><h3>Style guides</h3><p>Boost developer experience with a styleguide. Developers and designers can iterate faster on generalized components.</p><p>List of living style guide projects worth mentioning</p><ul><li><a href="https://react-styleguidist.js.org/">styleguidist</a> for multiple frameworks</li><li><a href="https://storybook.js.org/">storybook</a> for React only</li><li><a href="https://www.docz.site">docz</a> for React only</li></ul><p>Example of public documentation/styleguide using <a href="https://www.docz.site/">docz</a>. <a href="https://ableneo.github.io/modules/">https://ableneo.github.io/modules/</a></p><h3>Conclusion</h3><p>The main goal is to enable fast and reliable development supporting the business needs of the customer. Use tools that fit the project, developers and designers. Try to remove repeatable tasks by automatization from the workflow.</p><p>👏Clap, 👂follow for more awesome 💟#Javascript and ⚛️#automatization content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b0dd7aaf810" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ableneo/best-practices-for-javascript-projects-4b0dd7aaf810">Best practices for Javascript projects</a> was originally published in <a href="https://medium.com/ableneo">ableneo tech &amp; transformation</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚛️ Focused Styling in React and refactoring of Mobx]]></title>
            <link>https://medium.com/ableneo/%EF%B8%8F-focused-styling-in-react-and-refactoring-of-mobx-238303853958?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/238303853958</guid>
            <category><![CDATA[mobx]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[mobx-react]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[emotionjs]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Tue, 19 Mar 2019 01:30:35 GMT</pubDate>
            <atom:updated>2020-07-08T19:30:27.074Z</atom:updated>
            <content:encoded><![CDATA[<p>Are you using React on the project with an external theme? Read more theming of for React, some hints for mobx without decorators and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*feF7z11YNylMSBTWXOqvFw.jpeg" /></figure><p>This article is for anyone who is</p><ul><li>working with React</li><li>is planning to start working with React in the near future</li><li>likes practical examples ❤️</li><li>uses Mobx</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yibTaVlDjWHlEWcz" /><figcaption>Photo by <a href="https://unsplash.com/@alicegrace?utm_source=medium&amp;utm_medium=referral">Alice Achterhof</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Styling</h3><p>Unqualified styling can create the worst technical debt possible. Try to write a minimum of new styles as possible.</p><ul><li>🚨style only using class name selectors!</li><li>🚧do not nest selectors!</li><li>🚨use class names that start with <strong>“.js-”</strong> for javascript functionality never for styling</li></ul><p><a href="https://medium.com/ableneo/theming-guidelines-rules-for-styling-d8589fc344b6">Rules for theming and Styling with CSS, SCSS</a></p><h4>Mobile first</h4><ul><li>Style simple components to take a full width</li><li>Layout components should scale up elements as the viewport changes</li><li>Use only media query based on minimum viewport widths<br>@media (min-width: ___px) { ... }</li><li>In SCSS prefer mixins for <a href="https://getbootstrap.com/docs/4.0/layout/overview/#responsive-breakpoints">media queries from Bootstrap 4</a><br>@include media-breakpoint-up(size){...} // is all you need to use</li></ul><h4>Theming</h4><p>Employ component library like bootstrap. Use the provided components and make customization exclusively by changing Sass variables.</p><ul><li><a href="https://medium.com/ableneo/theming-guidelines-customize-bootstrap-of-other-toolkits-f11fb9dd0a87">Customize Bootstrap or other toolkits, ui-frameworks or ui-libraries</a></li><li><a href="https://medium.com/ableneo/theming-guidelines-rules-for-html-in-portlets-f7121982d931">Rules for HTML in systems with theming</a></li></ul><blockquote>Any code is generally clearer and easier to maintain when it does not use globals, CSS styles are global</blockquote><h4>Components should own styles</h4><p>Solution to global styles is to make write styles inside of every component using CSS in the JS library like styled-components or <a href="https://emotion.sh/docs/introduction">emotion</a>.</p><blockquote><a href="https://emotion.sh/docs/introduction">Emotion</a> is a library designed for writing CSS styles with JavaScript</blockquote><p><a href="https://medium.com/ableneo/example-of-a-component-with-styled-components-in-defaultprops-612c0f5ac386">Example of a component with styled components in defaultProps</a></p><h3>Component design</h3><p>Thinking in react way. A component should use data to render UI. Design simple components that do only one thing. Components used for Layout and styling should not know about the application model.</p><blockquote>function (data) { return UI; }</blockquote><h4>🏗 Component Categories</h4><p><strong>🧱 The base styled components</strong></p><ul><li>Elements with styles</li></ul><p><strong>💅 Presentational components</strong></p><ul><li>Reusable components with Styles</li></ul><p><strong>🎁 Container presenter components</strong></p><ul><li>Customized Presentational Components that know about application Model</li></ul><p><strong>🎛 Container components</strong></p><ul><li>Only inject data and behavior to Container presenter components</li></ul><p><a href="https://medium.com/ableneo/categorization-of-react-components-a8276c77ac72">Categorization of React Components</a></p><h3>State management</h3><h4>⚛️React introduced Hooks</h4><p>Hooks solve state management without an additional library.</p><h4>Components should not misuse specific state management library</h4><p>Consider a situation when the creator of mobx will make this project deprecated. If a project has components coupled with mobx, all the components will need to change, compared with only container components have a connection to the state using inject or connect function and the refactorings are much easier.</p><ul><li>decorators make components harder to test</li><li>using store inside of the components requires to mock the whole store for testing</li></ul><blockquote>Instead, we should use inject and observer as a functions</blockquote><blockquote><a href="https://github.com/mobxjs/mobx-react#inject-as-function">https://github.com/mobxjs/mobx-react#inject-as-function</a></blockquote><h4>👍 Benefits of using inject and observer functions:</h4><p>you are not using generators that are not part of the Javascript specification. (🤯 Currently unstable proposal)</p><ul><li>🚀 the code is future proof, and you do not have to change anything when new generators are released</li></ul><p>you can prepare data and actions inside of the inject</p><ul><li>🍀 you can work with simple, functional components</li><li>♻️ your components will not know about the store and can be reused</li></ul><p>Example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b727413af792f66b5389b37e02511a6f/href">https://medium.com/media/b727413af792f66b5389b37e02511a6f/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F9o895wqzww%3Fautoresize%3D1%26fontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F9o895wqzww%3Fautoresize%3D1%26fontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F9o895wqzww%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/c202a893a865de1af055cf100e6025fc/href">https://medium.com/media/c202a893a865de1af055cf100e6025fc/href</a></iframe><h3>Use of Lerna with yarn workspaces and packages generator</h3><p>Consider use of a monorepo project with</p><ul><li>eslint config with prettier</li><li>precommit and prepush hooks build in</li><li>create new packages using package generators</li><li>one command versioning with an automatic changelog</li><li>releasing of all packages with one command</li></ul><p>Link to example <a href="https://github.com/ableneo/tools">project</a> and <a href="https://github.com/ableneo/tools/tree/master/_templates/package/with-prompt">link to generator folder in the project</a><br>The styleguide, eslint config could be moved into this repository and released from here. It can enable to develop common packages faster with the current setup and we can create smaller packages with little to no overhead.</p><p>More about how to create a simple generator:</p><p><a href="https://medium.com/ableneo/how-to-use-the-hygen-code-generator-4bab25d99d8b">How to use the hygen code generator</a></p><p>👏Clap, 👂follow for more awesome 💟#Javascript and ⚛️#React content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=238303853958" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ableneo/%EF%B8%8F-focused-styling-in-react-and-refactoring-of-mobx-238303853958">⚛️ Focused Styling in React and refactoring of Mobx</a> was originally published in <a href="https://medium.com/ableneo">ableneo tech &amp; transformation</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use the hygen code generator]]></title>
            <link>https://medium.com/ableneo/how-to-use-the-hygen-code-generator-4bab25d99d8b?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bab25d99d8b</guid>
            <category><![CDATA[developer-experience]]></category>
            <category><![CDATA[hygen]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[generator]]></category>
            <category><![CDATA[developer-tools]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Wed, 13 Mar 2019 12:58:58 GMT</pubDate>
            <atom:updated>2023-02-07T10:24:47.290Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to use the Hygen code generator</h3><p>There are platforms that list thousands of generators namely yeoman but often you will need something simple and custom. The alternative is to use <a href="https://www.hygen.io/">Hygen</a> for generating custom project sections.</p><blockquote>Hygen is using javascript for prompt and EJS for templating but is fully capable of generating code in any language.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tYZncYpGAfmRgHJ3" /><figcaption>Photo by <a href="https://unsplash.com/@bank_phrom?utm_source=medium&amp;utm_medium=referral">Bank Phrom</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fxKOrekolOqaWc0uyjgPMg.png" /><figcaption><a href="https://www.hygen.io/">https://www.hygen.io/</a></figcaption></figure><h3>Start with creating the project</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ZtDuI4smtRSQWwovF-KXQ.png" /><figcaption>Go to <a href="https://codesandbox.io/">https://codesandbox.io/</a> and create a new node project</figcaption></figure><h3>Saving will create your personal copy</h3><p>Then you can open a new terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zR0_-tbpJ7niNMWVCqmUmw.png" /><figcaption>1. Save 2. Hide browser 3.add new terminal</figcaption></figure><h3>Initialize Hygen generator</h3><p>Write into the following command into the terminal.</p><pre>npx hygen init self</pre><p>you should see an output like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JXkHZCdqf18EeEQlgr2edQ.png" /><figcaption>npx hygen init self</figcaption></figure><p>Now we have a generator that will be used to create other generators</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*PAlpTjKSogmiZ_Wl.jpg" /><figcaption>You can generate meme as well <a href="https://imgflip.com/memegenerator/Yo-Dawg-Heard-You">https://imgflip.com/memegenerator/Yo-Dawg-Heard-You</a></figcaption></figure><h3>Generate a with-prompt generator</h3><p>We will be using prompt to ask questions in the console. <a href="https://github.com/enquirer/enquirer/tree/master/examples">See examples of prompts using enquirer</a>.</p><pre>npx hygen generator with-prompt readme</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CGL8JW85sV1LlVt0bTvzYA.png" /></figure><h3>Now we can change the template files</h3><p>Update _templates/readme/with-prompt/hello.ejs.t to:</p><pre>---</pre><pre>to: README.md</pre><pre>---</pre><pre># &lt;%= name %&gt;</pre><pre>&lt;%= message %&gt;</pre><p>Update _templates/readme/with-prompt/prompt.js to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22a98c7ddcd893f26a3cc5ef73523646/href">https://medium.com/media/22a98c7ddcd893f26a3cc5ef73523646/href</a></iframe><h3>Run the generator and create README.md</h3><p>Run following command in Terminal</p><pre>npx hygen readme with-prompt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MHtnGo0h6xpr-Q0obsSGcw.png" /><figcaption>The output of the generated file</figcaption></figure><h3>Run a script in from template frontmatter</h3><p>Update _templates/readme/with-prompt/hello.ejs.t to:</p><pre>---</pre><pre>to: README.md</pre><pre>sh: curl -s https://www.toptal.com/developers/gitignore<em>/api/archive,macos,linux,windows,node,jetbrains,sublimetext,eclipse,netbeans,visualstudiocode &gt; .gitignore</em></pre><pre>---</pre><pre># &lt;%= name %&gt;</pre><pre>&lt;%= message %&gt;</pre><p>The output of the shell script will create .gitignore file in your project. Curl will return it from <a href="https://www.toptal.com/developers/gitignore">https://www.toptal.com/developers/gitignore</a> <em>API and pipe it to </em>.gitignore<em>.</em></p><h3>Final project</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fzlnw20o91p%3Fautoresize%3D1%26expanddevtools%3D1%26fontsize%3D14%26module%3D%252FREADME.md%26moduleview%3D1%26view%3Deditor&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fzlnw20o91p%3Fautoresize%3D1%26expanddevtools%3D1%26fontsize%3D14%26module%3D%252FREADME.md%26moduleview%3D1%26view%3Deditor&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fzlnw20o91p%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/be7ceb6c3a9a01d1146eb152786569a8/href">https://medium.com/media/be7ceb6c3a9a01d1146eb152786569a8/href</a></iframe><h3>Conclusion</h3><p>The sky is the limit when using generators. Hygen provides more options like injecting into existing files or running shell scripts, all the examples are in <a href="https://www.hygen.io/templates">the documentation Hygen.io</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7B3jth0LwKaJ_cYh6Mjyw.jpeg" /></figure><p>Read more about generators in general in the previous article.</p><p><a href="https://medium.com/ableneo/improve-your-javascript-developer-experience-by-generating-code-d10f7f2e9b6d">Improve your Javascript Developer Experience by generating code</a></p><p>👏Clap, 👂follow for more awesome 💟#Javascript and ⚛️#automatization content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bab25d99d8b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ableneo/how-to-use-the-hygen-code-generator-4bab25d99d8b">How to use the hygen code generator</a> was originally published in <a href="https://medium.com/ableneo">ableneo tech &amp; transformation</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improve your Javascript Developer Experience by generating code]]></title>
            <link>https://medium.com/ableneo/improve-your-javascript-developer-experience-by-generating-code-d10f7f2e9b6d?source=rss-4b9acead2b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d10f7f2e9b6d</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[generator]]></category>
            <category><![CDATA[developer-experience]]></category>
            <category><![CDATA[code-generation]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Marcel Mokos]]></dc:creator>
            <pubDate>Wed, 13 Mar 2019 12:41:23 GMT</pubDate>
            <atom:updated>2020-07-29T14:47:04.483Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kLTcTlDEvJ4btUfJObqMmw.jpeg" /></figure><p>No one wants to spend time creating boilerplate. Generating repeating code patterns can speed up development tremendously. What are the options? Read more to find out.</p><blockquote>Choosing a generator and creating templates is an investment. Larger teams can experience faster development time and an increase of code consistency.</blockquote><h3>Code snippets</h3><p>Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional statements in the code editor.</p><blockquote>Autocomplete will suggest a code snippet</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xZK9Xoas4buHGj3v" /><figcaption>Photo by <a href="https://unsplash.com/@siniz?utm_source=medium&amp;utm_medium=referral">Siniz Kim</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>👍Great for repetitive small chunks of code<br>👍Easy to set up</p><p>👎Limited use of templating and placeholders<br>👎Not build to generate files with specific names</p><h4>Code snippets in the editor</h4><blockquote>Snippets are helpful but hard to share in teams and specific to the editor</blockquote><p>👍All major code editors provide this option natively or with a plugin<br>👍Easy to set up, many available as plugins</p><p>👎Editor specific local settings<br>👎Not easily sharable to other team members<br>👎Can not generate multiple named files</p><p>Examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/0*Q6L0yywBZOOOlkKe.gif" /><figcaption>Creating your own snippets in VScode <a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets">https://code.visualstudio.com/docs/editor/userdefinedsnippets</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s8sPnq37hUThFx5ERQvJDg.gif" /><figcaption>Using and creating code snippets in JetBrains Editors <a href="https://blog.jetbrains.com/webstorm/2018/01/using-and-creating-code-snippets/">https://blog.jetbrains.com/webstorm/2018/01/using-and-creating-code-snippets/</a></figcaption></figure><h4>Code snippet managers as stand-alone apps</h4><blockquote>Stand alone apps for snippet management are often not multi platform or do not have team sharing functionalities</blockquote><h3>Bash, NPM or other scripts</h3><p>Bash has many options for working with the file system. Combining it with NPM scripts located in package.json with some work can qualify as a code generator tool.</p><blockquote><a href="https://github.com/marcelmokos/eslint-config-with-prettier#running-setup-script">Running setup script</a> from <a href="https://gist.github.com/marcelmokos/8cb21782167f66847eb739790f2f0a06">GitHub gist</a> in <a href="https://www.npmjs.com/package/eslint-config-with-prettier">eslint-config-with-prettier</a> project and output <a href="https://github.com/marcelmokos/eslint-config-with-prettier/tree/master/example">example</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*he1JQHxUcQyYlFTv" /><figcaption>Photo by <a href="https://unsplash.com/@goodncrazy?utm_source=medium&amp;utm_medium=referral">Carissa Rogers</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Forking a boilerplate project from GitHub</h3><p>I would say one of the overused technique to start a project is to fork a boilerplate. Can not be recommended for every use case.</p><blockquote>Forking from GitHub will help you create a project structure and setup build</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rLuH7ambOPyKlhws" /><figcaption>Photo by <a href="https://unsplash.com/@fancycrave?utm_source=medium&amp;utm_medium=referral">Fancycrave</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>👍If you do it right you can still consume some updates from original projects<br>👍Can be shared and published</p><p>👎Sometimes hard to find one with technologies and opinions you prefer<br>👎Every customization makes consuming updates more difficult<br>👎Once you fork you have to maintain pulls from the original project</p><blockquote>Some boilerplate projects have generators build in. An excellent example is <a href="https://github.com/react-boilerplate/react-boilerplate/tree/master/internals/generators">react-boilerplate</a> with 21,6k github ⭐️ that uses <a href="https://plopjs.com/">plopjs</a> that will be introduced later.</blockquote><h3>Creating a project from the codesandbox.io templates</h3><h4><a href="https://codesandbox.io/explore">Codesandbox.io</a> as an editor</h4><p>Great option if you want to try web technology and edit code with code editor in your browser. Sharing code is phenomenal if you have not tried it you will be surprised how useful it is for some situations.</p><h4><a href="https://codesandbox.io">Codesandbox.io</a> as a generator</h4><p>The easiest and most practical list of project templates you can find. Basically, it is similar to forking a boilerplate project. But the platform is providing full-featured code editor with the live preview and sharing.</p><blockquote>Go the website click on the programing language and technology you want to try and in few seconds you are live coding</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7s1bjiZVzKQPPDED" /><figcaption>Photo by <a href="https://unsplash.com/@billjelen?utm_source=medium&amp;utm_medium=referral">Bill Jelen</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1JHeoZO5wMOIG26S1leUZA.png" /><figcaption><a href="https://codesandbox.io">https://codesandbox.io</a></figcaption></figure><p>Pros and cons are similar to forking a project.</p><p>👍list of project templates that work without configuration and setup of the environment<br>👍build and linting setup can be hidden and automatically updated</p><h3>Generators</h3><p>Where code snippets were simple and mainly focused on developer workflow with repeating parts of the program, generators are focused on scaffolding new projects, and sections like new controllers with unit tests.</p><blockquote>Parametrized command line tool outputing application or project section</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*23lEp2yQcjXjfoPQ" /><figcaption>Photo by <a href="https://unsplash.com/@sakulich?utm_source=medium&amp;utm_medium=referral">Sergei Akulich</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Pros and cons are similar to forking a boilerplate project from Github<br>👍Some generators provide an update mechanism for generated code, but most of them don’t<br>👍Allows you to generate sections of the app <br>👍Helps to follow code standards</p><p>👎Can be hard to customize for the project, technology, and team needs</p><h4>Frameworks containing generators</h4><p>Command line tools allow you to use templates to create a whole lot of things. One of the frameworks that is notoriously famous for its use of generators was Ruby on Rails with 42k GitHub ⭐️. There is native support for creating new generators in the framework and you can install more generators through generator gems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dKdUagWoJFg7gbZ60j2xtw.png" /><figcaption>Rails and generators <a href="https://guides.rubyonrails.org/command_line.html#rails-generate">https://guides.rubyonrails.org/command_line.html#rails-generate</a></figcaption></figure><p><a href="http://nodeframework.com/"><strong>Node Frameworks</strong></a><strong> examples<br></strong>- <a href="https://sailsjs.com/documentation/concepts/extending-sails/generators/available-generators">SailsJs available generators</a> have Rails-like options for generating app sections<br>- <a href="https://expressjs.com/en/starter/generator.html">ExpressJs application generator</a> is providing only project generator with options, there are many generators from the community</p><blockquote>Angular has <a href="https://cli.angular.io/">CLI</a> that can <a href="https://angular.io/cli/generate">ng generate</a> project and sections</blockquote><p>👍Some frameworks provide an update mechanism for generated code, but most of them don’t<br>👍Allows you to generate sections that follow framework code standards</p><p>👎Can be hard to customize for the project, technology, and team needs</p><h4>Generators for boilerplate projects</h4><p>Some projects are providing an app generator as a key feature of the project. <a href="https://facebook.github.io/create-react-app/">Create React App</a> (64k ⭐️)is helping to set up a modern web app by running one command.</p><p>👍Staring point for rapid development</p><p>👎The generator is only for app boilerplate, missing section generators<br>👎Can be hard to customize for the project, technology, and team needs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*23TENiKGRlScU86FLxkH0A.gif" /><figcaption>Create React App <a href="https://facebook.github.io/create-react-app/">https://facebook.github.io/create-react-app/</a></figcaption></figure><h3>Tools to create and share project generators</h3><h4><a href="https://yeoman.io">Yeoman</a></h4><p>Yeoman helps you to kickstart new projects, prescribing best practices and tools to help you stay productive.</p><blockquote>Mainly globally installed CLI tool with globally installed specialized generators</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iSsZd1GfZbUfq1JV" /><figcaption>Photo by <a href="https://unsplash.com/@mmlightworks?utm_source=medium&amp;utm_medium=referral">Moritz Mentges</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*xbnJ4S46rXPaRgVt.png" /><figcaption><a href="https://yeoman.io/">https://yeoman.io/</a></figcaption></figure><blockquote>There are 8145 generators published on <a href="https://yeoman.io/generators/">Yeoman generators platform</a>, most popular is <a href="https://www.jhipster.tech/">jhipster</a> for spring boot and Angular/React with nearly 13k ⭐️ on github as of march of 2019</blockquote><p>👍Many ready to be used full featured generators<br>👍Using <a href="https://ejs.co/">EJS</a> template language that can embed javascript in templates<br>👍Documentation, options, helpers for unit testing and debugging</p><p>👎Is promoted to be used as a global dependency on the local machine<br>👎Sharing locally installed global dependency is not meant for teams</p><p>Yeoman generator can be located in a project subfolder. But will have use <a href="https://docs.npmjs.com/cli/link.html">npm link</a> or <a href="https://yarnpkg.com/lang/en/docs/workspaces/">yarn workspaces</a> that are not well known and documented.</p><h4><a href="https://plopjs.com/">Plop</a></h4><p>A plop is a little tool that saves you time and helps your team build new files with consistency. It is used mainly as a project dependency. Plop uses the <a href="http://handlebarsjs.com/">handlebars</a> template engine to generate your files.</p><blockquote>Micro-generator framework that makes it easy for an entire team to create files with a level of uniformity</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1ScLpuhpuKE6-y7q" /><figcaption>Photo by <a href="https://unsplash.com/@andrewruiz?utm_source=medium&amp;utm_medium=referral">Andrew Ruiz</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/0*mPnRfJotR_Ps87t4" /><figcaption><a href="https://github.com/amwmedia/plop">https://github.com/amwmedia/plop</a></figcaption></figure><p>👍Better suited for in project generator then Yeoman</p><p>👎Uses the <a href="http://handlebarsjs.com/">handlebars</a> template engine that is less powerful than <a href="https://ejs.co/">EJS</a></p><h4><a href="https://www.hygen.io/">Hygen</a></h4><p>The scalable code generator that saves you time.</p><p>Is less popular than Plop but provides similar value to the project. Hygen is sharing <a href="https://ejs.co/">EJS</a> templating language with Yeoman allowing you to easily migrate between the two. Creating and updating generators is simplified and files can be easily included in the project. Hygen can be a perfect fit as a project-specific generator improving the developer experience.</p><blockquote>Hygen is the simple, fast, and scalable code generator framework that lives in your project.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SSUmu6uD_2kTaf50" /><figcaption>Photo by <a href="https://unsplash.com/@juliandufort?utm_source=medium&amp;utm_medium=referral">Julian Dufort</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>CLI for generating and using project specific generators</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fxKOrekolOqaWc0uyjgPMg.png" /><figcaption><a href="https://www.hygen.io/">https://www.hygen.io/</a></figcaption></figure><p>👍Self-contained in the project <br>👍Using <a href="https://ejs.co/">EJS</a> template language that can embed javascript in templates<br>👍Templates have a markdown-like frontmatter section for configuration</p><p>👎Missing native helpers for testing</p><h3>Conclusion</h3><p>Generators are an investment that saves time, in the long run, the benefit will be better developer experience and improved code standards. Consider using them in your projects.</p><p>Chose a framework that has the best generator for your project needs. In some cases there you will miss some features or want to make changes then just fork the generator you like the most. If there is no generator that can solve your use case, consider creating your own custom generator.</p><h3>Recent work with generators</h3><p>I have used Plop in the past to generate</p><ul><li>React Components that had types, style guide config, tests, translations and styles generated</li><li>Redux Ducks with the state using Immutable.js Records, that had typed Action creators, reducers, Sagas based on <a href="https://www.npmjs.com/package/redux-inject-reducer-and-saga">redux-inject-reducer-and-saga</a></li></ul><p>I have used Bash to generate files that set up eslint with prettier</p><ul><li><a href="https://www.npmjs.com/package/eslint-config-with-prettier#running-setup-script">How to run the script in the readme of eslint-config-with-prettier</a> that output following <a href="https://github.com/marcelmokos/eslint-config-with-prettier/tree/master/example">example project</a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/629b8434ee942de8a1dc584be010528a/href">https://medium.com/media/629b8434ee942de8a1dc584be010528a/href</a></iframe><p>But now I am moving from Plop and Bash scripts towards Hygen.</p><ul><li>My recent generator is creating packages in a project using <a href="https://github.com/lerna/lerna">Lerna</a> and <a href="https://yarnpkg.com/lang/en/docs/workspaces/">Yarn workspaces</a></li><li>link to <a href="https://github.com/ableneo/tools">project</a> and <a href="https://github.com/ableneo/tools/tree/master/_templates/package/with-prompt">link to generator folder</a></li></ul><h4>Read more in the following article how to use Hygen microgenerator framework</h4><p><a href="https://medium.com/ableneo/how-to-use-the-hygen-code-generator-4bab25d99d8b">How to use the hygen code generator</a></p><p>👏Clap, 👂follow for more awesome 💟#Javascript and ⚛️#automatization content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d10f7f2e9b6d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ableneo/improve-your-javascript-developer-experience-by-generating-code-d10f7f2e9b6d">Improve your Javascript Developer Experience by generating code</a> was originally published in <a href="https://medium.com/ableneo">ableneo tech &amp; transformation</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>