<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vladlen</title>
    <description>The latest articles on DEV Community by Vladlen (@vladlenskiy).</description>
    <link>https://dev.to/vladlenskiy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1178568%2Ffdbbd49b-f222-4a09-94aa-fa03cb6efe1a.png</url>
      <title>DEV Community: Vladlen</title>
      <link>https://dev.to/vladlenskiy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vladlenskiy"/>
    <language>en</language>
    <item>
      <title>Creating Custom React Native Templates: A Step-by-Step Guide</title>
      <dc:creator>Vladlen</dc:creator>
      <pubDate>Tue, 10 Oct 2023 09:17:31 +0000</pubDate>
      <link>https://dev.to/vladlenskiy/creating-custom-react-native-templates-a-step-by-step-guide-d46</link>
      <guid>https://dev.to/vladlenskiy/creating-custom-react-native-templates-a-step-by-step-guide-d46</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qJEQDqLo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AqyCdlXHEsEseKjUZA3JJVg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qJEQDqLo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AqyCdlXHEsEseKjUZA3JJVg.png" alt="" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;React Native has gained immense popularity for building cross-platform mobile applications. While React Native offers a fantastic starting point with its default template, sometimes you may want to create a custom template to streamline your development process or enforce coding standards across multiple projects. In this article, we'll walk you through the steps to create your own React Native template.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Create Custom Templates?
&lt;/h3&gt;

&lt;p&gt;There are several reasons to create custom templates for your React Native projects:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Code Reusability&lt;/strong&gt; : You can include reusable components, libraries, and styles in your templates. This promotes code reuse across different projects, saving development effort and reducing the chance of bugs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best Practices&lt;/strong&gt; : You can enforce best practices and architectural patterns by including them in your custom template.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster Development&lt;/strong&gt; : With a template, you don't have to start from scratch. You can leverage the boilerplate code, configurations, and UI components to accelerate development.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Onboarding&lt;/strong&gt; : Templates simplify the onboarding process for new team members. They can quickly understand the project structure and development practices, leading to faster productivity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduced Errors&lt;/strong&gt; : By using templates with predefined configurations and dependencies, you reduce the likelihood of configuration errors and compatibility issues.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before creating a custom &lt;strong&gt;React Native&lt;/strong&gt; template, make sure you have the following prerequisites in place:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt; : Ensure you have Node.js installed on your machine. You can download it from &lt;a href="https://nodejs.org/"&gt;nodejs.org&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React Native CLI&lt;/strong&gt; : Install the React Native CLI globally using the following command:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g react-native-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Steps to Create a Custom Template
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Step 1: Initialize a New Template Project
&lt;/h4&gt;

&lt;p&gt;First, create a new directory for your &lt;strong&gt;custom template&lt;/strong&gt;  project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir custom-rn-template
cd custom-rn-template
npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your package.json file should looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "MyCustomTemplate",
  "version": "1.0.0",
  "description": "React Native Custom Template",
  "files": [
    "template",
    "template.config.js"
  ]
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create template.config.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  placeholderName: 'MyCustomTemplate',
  templateDir: './template',
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, use the &lt;strong&gt;React Native CLI&lt;/strong&gt; to initialize a new project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init MyCustomTemplate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that rename “MyCustomTemplate” folder to “template”.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Customize Your Template
&lt;/h4&gt;

&lt;p&gt;Now that you have a base project, you can customize it to fit your needs. You can make various modifications, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Project Structure&lt;/strong&gt; : Organize your project structure the way you prefer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependencies&lt;/strong&gt; : Add or remove dependencies by modifying the package.json file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Boilerplate Code&lt;/strong&gt; : Include common components, utilities, or screens that you frequently use in your projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Configuration&lt;/strong&gt; : Set up linting, testing, and other configurations that align with your development practices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 3: Document Your Template
&lt;/h4&gt;

&lt;p&gt;To make your custom template user-friendly, create documentation that explains how to use it. You can include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Installation&lt;/strong&gt; : Explain how to create a new React Native project using your template.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customization&lt;/strong&gt; : Provide guidance on how to customize the template further.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage&lt;/strong&gt; : Describe any additional steps or configurations required for specific features or libraries included in the template.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 4: Publish Your Template
&lt;/h4&gt;

&lt;p&gt;Once you’ve customized and documented your template, it’s time to publish it. You can publish your template as an npm package, making it accessible to your team and the community.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an account on &lt;a href="https://www.npmjs.com/?ref=hackernoon.com"&gt;npmjs.com&lt;/a&gt; if you don’t have one already.&lt;/li&gt;
&lt;li&gt;Navigate to your template project directory and log in to npm:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Publish your template to npm:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm publish --access public
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 5: Use Your Custom Template
&lt;/h4&gt;

&lt;p&gt;To create a new React Native project using your custom template, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init MyCustomApp --template MyCustomTemplate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace “MyCustomApp” with the name of your new project. React Native will generate a new project based on your custom template.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Creating custom React Native templates can significantly improve your development workflow by enforcing best practices, maintaining consistency, and saving time on project setup. Also check my own &lt;a href="https://www.npmjs.com/package/react-native-modular-template?ref=hackernoon.com"&gt;react-native-modular-template&lt;/a&gt;, which includes what I use when creating new projects.&lt;/p&gt;

</description>
      <category>androidappdevelopmen</category>
      <category>iosappdevelopment</category>
      <category>react</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>Optimizing React Native Project Structure: The Modular Architecture Approach</title>
      <dc:creator>Vladlen</dc:creator>
      <pubDate>Fri, 06 Oct 2023 10:48:45 +0000</pubDate>
      <link>https://dev.to/vladlenskiy/optimizing-react-native-project-structure-the-modular-architecture-approach-1ga3</link>
      <guid>https://dev.to/vladlenskiy/optimizing-react-native-project-structure-the-modular-architecture-approach-1ga3</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wB82UWVR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AwvATmxlb6ijyGJPAMGEB5A.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wB82UWVR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AwvATmxlb6ijyGJPAMGEB5A.jpeg" alt="" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, I will share my experience of structuring projects, which I have been successfully using for three years in my &lt;strong&gt;React Native&lt;/strong&gt; projects. I think that structuring a project by file types is not the best approach, although it works well in some situations. My team and I use something similar to modular architecture for our projects, and we want to share it with you!&lt;/p&gt;

&lt;h3&gt;
  
  
  🚩 Problem
&lt;/h3&gt;

&lt;p&gt;There are several approaches to creating the structure of client applications. The most common, but not the most convenient one, is splitting the project by file type. &lt;strong&gt;The&lt;/strong&gt;  &lt;strong&gt;main problem&lt;/strong&gt; is that the logic of one module is “smeared” over the whole project. In this approach, the structure usually looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;api
components
containers
&lt;/span&gt;&lt;span class="gd"&gt;- HomeContainer.tsx
- ProfileContainer.tsx
- SettingsContainer.tsx
&lt;/span&gt;&lt;span class="p"&gt;store
App.jsx
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  🙌🏻 Solution
&lt;/h3&gt;

&lt;p&gt;More convenient and scalable is the approach of dividing the project by functionality. We call such top-level units, into which the project is divided, modules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;src
&lt;/span&gt;&lt;span class="gd"&gt;- modules
- - auth
- - core
- - users
- - navigation
- - ud-ui
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When divided into modules, all components and logic are next to each other. It is easier to work with such a project: it is &lt;strong&gt;easier&lt;/strong&gt; to navigate the structure, delete and refactor modules, it is easier to see the overall picture of functionality, and there is less chance of interfering with each other during development. Functionality does not always mean business logic. There are functional modules, such as core, ud-ui, which are not tied to business logic.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Module Structure:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Domain (&lt;/em&gt; &lt;strong&gt;&lt;em&gt;An instrument in the hands of a conductor&lt;/em&gt;&lt;/strong&gt; &lt;em&gt; — Business logic of the module)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Store (&lt;/em&gt; &lt;strong&gt;&lt;em&gt;Conductor&lt;/em&gt;&lt;/strong&gt; &lt;em&gt; — Module control logic)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;UI (&lt;/em&gt; &lt;strong&gt;&lt;em&gt;Presentation&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  🪄 Domain lvl
&lt;/h3&gt;

&lt;p&gt;Typically, this layer contains interfaces, model descriptions, services to query the API, or business logic that is not related to a specific view (UI)&lt;/p&gt;

&lt;h4&gt;
  
  
  Structure of the Domain layer
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;enums
&lt;/span&gt;&lt;span class="gd"&gt;- UserRoleEnum.ts
&lt;/span&gt;&lt;span class="p"&gt;interfaces
&lt;/span&gt;&lt;span class="gd"&gt;- User.ts
&lt;/span&gt;&lt;span class="p"&gt;repositories
&lt;/span&gt;&lt;span class="gd"&gt;- UserRepository.ts
&lt;/span&gt;&lt;span class="p"&gt;resources
&lt;/span&gt;&lt;span class="gd"&gt;- UserResource.ts
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What can be stored at the Domain level?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Enums&lt;/li&gt;
&lt;li&gt;Interfaces&lt;/li&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;li&gt;Helpers&lt;/li&gt;
&lt;li&gt;Resources and Repositories (API)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  💾 Store lvl
&lt;/h3&gt;

&lt;p&gt;This layer is where the application is managed and interacts with the &lt;strong&gt;Domain&lt;/strong&gt; layer for API calls and changes to the &lt;strong&gt;Store&lt;/strong&gt;. Example of Store-level structure using &lt;strong&gt;Redux-Toolkit:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;entities
&lt;/span&gt;&lt;span class="gd"&gt;- index.ts
- selectors.ts
- actions.ts
&lt;/span&gt;&lt;span class="p"&gt;edit
&lt;/span&gt;&lt;span class="gd"&gt;- ...
&lt;/span&gt;&lt;span class="p"&gt;other-stores
&lt;/span&gt;&lt;span class="gd"&gt;- ...
&lt;/span&gt;&lt;span class="p"&gt;reducer.ts
selectors.ts
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Entities Store
&lt;/h4&gt;

&lt;p&gt;Usually, a separate store called “&lt;strong&gt;entities&lt;/strong&gt;” is used to &lt;strong&gt;store data&lt;/strong&gt;. This is a kind of &lt;strong&gt;database&lt;/strong&gt; for the client application to store entities of the same type. The other stores use identifiers if you need an entity that has already been loaded. So, if an entity is changed, it is changed in &lt;strong&gt;one place&lt;/strong&gt;  — entities store, and the rest of the program picks up the changes because it actually uses a reference to one common object.&lt;/p&gt;

&lt;h4&gt;
  
  
  Other stores
&lt;/h4&gt;

&lt;p&gt;Usually refers to individual pages or time-consuming actions, for example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;edit&lt;/strong&gt;  — user edit page&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;index&lt;/strong&gt;  — user list page&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;new&lt;/strong&gt;  — user creation page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  🖼️ UI lvl
&lt;/h3&gt;

&lt;p&gt;The UI layer contains elements related to data presentation, such as &lt;strong&gt;components&lt;/strong&gt;, &lt;strong&gt;screens&lt;/strong&gt; and &lt;strong&gt;hooks&lt;/strong&gt;. Usually, the layer is divided as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;screens
&lt;/span&gt;&lt;span class="gd"&gt;- profile
- - index.tsx
- - style.ts
- ...
&lt;/span&gt;&lt;span class="p"&gt;components
&lt;/span&gt;&lt;span class="gd"&gt;- users-list
- - index.tsx
- - style.ts
- ...
&lt;/span&gt;&lt;span class="p"&gt;hooks
&lt;/span&gt;&lt;span class="gd"&gt;- useUserForm.ts
- ...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Screens
&lt;/h4&gt;

&lt;p&gt;This folder contains components that are directly assigned in routing, i.e., they are screens or pages in the navigation structure of the application.&lt;/p&gt;

&lt;h4&gt;
  
  
  Components
&lt;/h4&gt;

&lt;p&gt;Components that relate to the module’s business logic. Can be used outside the module but are necessarily inside its structure&lt;/p&gt;

&lt;h3&gt;
  
  
  Divide and rule!
&lt;/h3&gt;

</description>
      <category>projectstructure</category>
      <category>react</category>
      <category>modulararchitecture</category>
      <category>reactnative</category>
    </item>
  </channel>
</rss>
