<?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: Ilya Azovtsev</title>
    <description>The latest articles on DEV Community by Ilya Azovtsev (@ilya_azovtsev).</description>
    <link>https://dev.to/ilya_azovtsev</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%2F781397%2F6a64cef2-96a6-4f19-9299-e45cf5911168.jpg</url>
      <title>DEV Community: Ilya Azovtsev</title>
      <link>https://dev.to/ilya_azovtsev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ilya_azovtsev"/>
    <language>en</language>
    <item>
      <title>How to automate PDF generation of dashboards/web pages with open-source Puppeteer web automation tool</title>
      <dc:creator>Ilya Azovtsev</dc:creator>
      <pubDate>Mon, 09 May 2022 11:47:29 +0000</pubDate>
      <link>https://dev.to/browserless/how-to-automate-pdf-generation-of-dashboardsweb-pages-with-open-source-puppeteer-web-automation-tool-4l1a</link>
      <guid>https://dev.to/browserless/how-to-automate-pdf-generation-of-dashboardsweb-pages-with-open-source-puppeteer-web-automation-tool-4l1a</guid>
      <description>&lt;p&gt;&lt;strong&gt;Send your clients a weekly or monthly report through email – they’ll be grateful!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;“Why do you pay for this product? What’s the real value, in numbers, of using this product?”.&lt;/p&gt;

&lt;p&gt;If you ask your clients this question, and they don’t know the “value” they get in numbers (like hours saved or clients generated with your tool) – they’re in a risk zone for churn 😬&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MCz-WuKX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kx3tzfi55ycgn1ufvo22.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MCz-WuKX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kx3tzfi55ycgn1ufvo22.gif" alt="Image description" width="250" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every SaaS company has dashboards and metrics that they share with clients on their platform. This is the place where clients actually understand how your tool or service helps them.&lt;/p&gt;

&lt;p&gt;Today, we’ll share with you how to save your clients’ time by sending report PDFs automatically to them so they don’t have to fetch them manually.&lt;/p&gt;

&lt;p&gt;And if you ask: “Why do I actually need it?”.&lt;/p&gt;

&lt;p&gt;I’ll tell you, this can improve your retention metrics:&lt;/p&gt;

&lt;p&gt;_Your clients automatically get reports -&amp;gt; they feel value from using your product/service -&amp;gt; they stay with you for a longer time -&amp;gt; you increase the Lifetime Value of the client _🚀&lt;/p&gt;

&lt;p&gt;Clients are always grateful when you can automate repetitive tasks such as downloading reports from your platform. This will only take about an hour to accomplish with browserless and will save your customers precious time.&lt;/p&gt;

&lt;p&gt;We’ll share with you a &lt;a href="https://dev.topuppeteer%20pdf%20generator"&gt;puppeteer pdf generator&lt;/a&gt; *&lt;em&gt;code snippet that you can copy &amp;amp; paste and save time even on coding *&lt;/em&gt;😅&lt;/p&gt;

&lt;h2&gt;
  
  
  How to automate PDF generation with Browserless
&lt;/h2&gt;

&lt;p&gt;Let’s illustrate this with our own browserless’ account dashboard. We can see the number of sessions that have run and our worker’s CPU &amp;amp; memory statistics. We’ll use our browserless API key to run the script and get the PDF returned.&lt;/p&gt;

&lt;p&gt;You can then make a simple NodeJS app to schedule that task and also send the PDF returned from browserless through email. Or you can send these PDFs via your current Email Marketing tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SE9soGGw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipwque39gdw85c07n0ae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SE9soGGw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipwque39gdw85c07n0ae.png" alt="Image description" width="880" height="777"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s Get Started&lt;/p&gt;

&lt;p&gt;First of all, create your &lt;a href="https://www.browserless.io/sign-up"&gt;Browserless account&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1skQO6Cd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dm5e3h0x7uqniqrrxx3z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1skQO6Cd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dm5e3h0x7uqniqrrxx3z.png" alt="Image description" width="880" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose the plan you want to go with; Usage-based with a free trial or Dedicated.&lt;/p&gt;

&lt;p&gt;Once you create the account, you’ll have the Dashboard (yes, we also have a dashboard 😀) with an API key, that you can use for automation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ffcpcobk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qv8vb98sehltsnyexcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ffcpcobk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qv8vb98sehltsnyexcw.png" alt="Image description" width="880" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To extract this dashboard, we can use the /function API to run the script below, where “token” is your API key from Browserless:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const puppeteer = require('puppeteer-core');

(async() =&amp;gt; {
    const token = "YOUR_API_KEY";
    const email = "YOUR_LOGIN_EMAIL";
    const password = "YOUR_LOGIN_PASSWORD";

    const browser = await puppeteer.connect({ browserWSEndpoint: 'wss://chrome.browserless.io?token='+token });
    const page = await browser.newPage();
    await page.setViewport({width:800,height:1020});
    await page.goto('https://cloud.browserless.io/account/',{ waitUntil: 'networkidle0'});
    await page.type('#login-email', email, {delay: 10});
    await page.type('#login-password', password, {delay: 10});
    await page.click('div.css-vxcmzt &amp;gt; div &amp;gt; button &amp;gt; span');
    await page.waitForSelector('.chartjs-render-monitor');
    await page.evaluate(() =&amp;gt; {
        var leftpanel = document.querySelector(".sticky_nav__3r2Ep");
        leftpanel.parentNode.removeChild(leftpanel);
        const date = new Date();
        document.querySelector('.text-white.mb-0').innerHTML="Sessions on "+date;
        document.querySelector('#app &amp;gt; div &amp;gt; div &amp;gt; div &amp;gt; .col-8').classList.add("col-12");
        document.querySelector('#app &amp;gt; div &amp;gt; div &amp;gt; div &amp;gt; .col-12').classList.remove("col-8");
    })
    await page.emulateMediaType('screen');
    return page.pdf({path:"dashboard.pdf",printBackground:true});
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s a simple script, we basically access the dashboard URL, login with our credentials, and click on the sign in button. Once the dashboard is loaded, we generate the PDF.&lt;/p&gt;

&lt;p&gt;First we import the puppeteer core library, which is lightweight since you’ll be connecting to a remote or existing chrome, and doesn’t come with browser binaries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const puppeteer = require('puppeteer-core');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’ll wrap all our code inside an async IIFE so that our code executes off the bat. Then we define our local variables, such as our API KEY, email, and password. The best practice here is to use process environments, but we’ll keep it simple for now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(async() =&amp;gt; {
    const token = "YOUR_API_KEY";
    const email = "YOUR_LOGIN_EMAIL";
    const password = "YOUR_LOGIN_PASSWORD";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s connect to the browserless WS endpoint by providing our API KEY and create a new browser and page to start automating.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const browser = await puppeteer.connect({ browserWSEndpoint: 'wss://chrome.browserless.io?token='+token });
const page = await browser.newPage();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that’s done, we’ll set the desired viewport&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.setViewport({
    width: 1920,
    height: 1080
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then go to the browserless account page and wait for the network traffic to settle down so that the email and password selectors are actually loaded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.goto('https://cloud.browserless.io/account/',
{ 
    waitUntil: 'networkidle0'
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We enter our credentials and click on the submit button – you can use environment variables for the password here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.type('#login-email', 'YOUR_EMAIL', {delay: 50});
await page.type('#login-password', 'YOUR_PASSWORD', {delay: 50});
await page.click('div.css-vxcmzt &amp;gt; div &amp;gt; button &amp;gt; span');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we’ve clicked log in, we want to wait to make sure the page is fully loaded by checking that the graph has been rendered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  await page.waitForSelector('.chartjs-render-monitor');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we want to modify the page before generating the PDF. We can do so inside the &lt;em&gt;page.evaluate()&lt;/em&gt; method. We are fetching the left panel navigation menu and removing it. Then we are finding the main panel that has the content that we want, we’ll remove the &lt;em&gt;.col-8&lt;/em&gt; class and add the &lt;em&gt;.col-12&lt;/em&gt; class so that it is fullscreen. You can feel free to modify the UI of your dashboard in this section, such as removing unwanted sections or adding new graphic elements by injecting html+css that you may want to show in the PDF.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.evaluate(() =&amp;gt; {
  var leftpanel = document.querySelector(".sticky_nav__3r2Ep");
  leftpanel.parentNode.removeChild(leftpanel); //removing the left panel
  const date = new Date();
  document.querySelector('.text-white.mb-0').innerHTML="Sessions on "+date; //adding the date in the title
  document.querySelector('#app &amp;gt; div &amp;gt; div &amp;gt; div &amp;gt; .col-8').classList.add("col-12"); //adding this class to be fullscreen
  document.querySelector('#app &amp;gt; div &amp;gt; div &amp;gt; div &amp;gt; .col-12').classList.remove("col-8"); //removing this class to overwrite the container size.
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After all your modifications are done, feel free to generate the pdf. It is common that CSS defaults to print CSS styles (in order to save ink when printing) so you can add these two lines of code to make the CSS look more like a user would usually look at it. Otherwise the CSS could shift and look weird.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.emulateMediaType('screen'); //will help not to render print css
return page.pdf({printBackground:true}); //will render backgrounds of your page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In some cases pages are rendering their fonts with web fonts, so if your page looks weird even after adding these two lines of code, it could be that the web fonts aren’t loading properly because the page detects you’re running chrome headless, and hence doesn’t see the need to render any fonts at all. To overcome this, you can either run the session headful or set the user agent manually as so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.setUserAgent(
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36'
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s an example of why setting these last two lines of code are relevant:&lt;/p&gt;

&lt;p&gt;Page with only page.pdf(); looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nfwdWTVo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e06eqpzfiv7qnogdzu2e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nfwdWTVo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e06eqpzfiv7qnogdzu2e.png" alt="Image description" width="880" height="827"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Page with print background looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wA7fM_wQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f83o8n8cz1c1f6rj80o3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wA7fM_wQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f83o8n8cz1c1f6rj80o3.png" alt="Image description" width="880" height="619"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;page with emulateMediaType set to screen looks like this (final result):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--474qSLjy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bs2eu40f8g52lvdovbr5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--474qSLjy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bs2eu40f8g52lvdovbr5.png" alt="Image description" width="880" height="829"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can take care of sending this PDF through your marketing platforms, have fun!&lt;/p&gt;

&lt;p&gt;👉 If you want to do this yourself, just create a &lt;a href="https://www.browserless.io/sign-up"&gt;Browserless account&lt;/a&gt; and get started!  &lt;/p&gt;

</description>
      <category>puppeteer</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to use JavaScript feature toggles to deploy safely [React.js example with Dev.to App]</title>
      <dc:creator>Ilya Azovtsev</dc:creator>
      <pubDate>Tue, 15 Feb 2022 12:54:13 +0000</pubDate>
      <link>https://dev.to/ilya_azovtsev/how-to-use-javascript-feature-toggles-to-deploy-safely-reactjs-example-with-devto-app-408g</link>
      <guid>https://dev.to/ilya_azovtsev/how-to-use-javascript-feature-toggles-to-deploy-safely-reactjs-example-with-devto-app-408g</guid>
      <description>&lt;p&gt;Feature flags aka Feature toggles in any language significantly reduce the blast radius of a release if anything goes wrong. Javascript feature flags are no exception. We already shared the guide on how to use &lt;a href="https://flagsmith.com/blog/nodejs-feature-flags/" rel="noopener noreferrer"&gt;feature flags in Node.js&lt;/a&gt;. In this post, you will learn how to use javascript feature toggles in a React.js application to deploy a small feature safely to your users. &lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Prior to diving deeper into the code and JavaScript feature toggles, below are some of the good to have requisites:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Some knowledge of Javascript and React.js would be essential&lt;/li&gt;
&lt;li&gt;Knowing how Node.js and Yarn work are required, knowledge of adding new packages with Yarn is also needed&lt;/li&gt;
&lt;li&gt;A Flagsmith account will be used to create the feature flag. &lt;a href="https://app.flagsmith.com/signup?utm_source=devto&amp;amp;utm_medium=javascript" rel="noopener noreferrer"&gt;Register now – It’s free&lt;/a&gt;. Flagsmith is the open-source product - &lt;a href="https://ilya.today/ghfsdevtojavascript" rel="noopener noreferrer"&gt;check out Github&lt;/a&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We will jump right into the code part now, brace yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: JavaScript feature flag with React.js Dev.to app
&lt;/h2&gt;

&lt;p&gt;We will build a simple React.js app that will list the latest articles from Dev.to. Dev is a community of software developers getting together to help one another out and this is the place where you read this article 😅. It is an amazing community where anyone can publish technical content without any editorial process. Based on &lt;a href="https://www.forem.com/" rel="noopener noreferrer"&gt;Forem&lt;/a&gt; it has a handy API and we are going to use the articles API to list the latest articles in a light React.js application.&lt;/p&gt;

&lt;p&gt;To create the &lt;a href="https://reactjs.org/docs/create-a-new-react-app.html" rel="noopener noreferrer"&gt;React.js application&lt;/a&gt; using create react app, we will 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 create-react-app devto-react 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will render output as follows when the setup is complete:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5aa50ynea3luxmvybawk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5aa50ynea3luxmvybawk.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we will quickly run the React.js boilerplate application to see if it is running with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd devto-react

yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will start the development server and open the default browser at &lt;code&gt;http://localhost:3000&lt;/code&gt; which looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6dbuxc2eaon5mz2xnuc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6dbuxc2eaon5mz2xnuc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hurray! Our skeleton React app created by Create React App for the JavaScript feature toggles tutorial is running. We will change the code to call the Dev.to API next.&lt;/p&gt;

&lt;p&gt;And will change the &lt;code&gt;src/App.js&lt;/code&gt; file to look like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';
import './App.css';
function App() {
  const [articles, setArticles] = useState([]);
  const [message, setMessage] = useState('loading…');
  useEffect(() =&amp;gt; {
    async function fetchArticles () {
      try {
        const data = await (await fetch('https://dev.to/api/articles/latest')).json();
        setArticles(data)
        const message = data.length ? "" : 'No articles found';
        setMessage(message);
      } catch (err) {
        console.log('err: ${err.message}', err);
        setMessage('could not fetch articles');
      }
    }
    fetchArticles()
  }, []);

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;header className="App-header"&amp;gt;
        &amp;lt;h2&amp;gt;Latest Dev.to articles&amp;lt;/h2&amp;gt;
        {message}
        &amp;lt;div className="articles"&amp;gt;
          &amp;lt;ul&amp;gt;
          {Array.isArray(articles) &amp;amp;&amp;amp; articles.map(
            article =&amp;gt; article.url &amp;amp;&amp;amp; &amp;lt;li&amp;gt;&amp;lt;a href={article.url} target="_blank" rel="noreferrer"&amp;gt;{article.title}&amp;lt;/a&amp;gt; – by {article.user.name}&amp;lt;/li&amp;gt;
          )}
          &amp;lt;/ul&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/header&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are using the &lt;a href="https://reactjs.org/docs/hooks-state.html" rel="noopener noreferrer"&gt;React useState&lt;/a&gt; hook to define two variables articles and the message. Then using the &lt;a href="https://reactjs.org/docs/hooks-effect.html" rel="noopener noreferrer"&gt;effect hook&lt;/a&gt; we are calling the Dev.to API in the &lt;code&gt;fetchArticles&lt;/code&gt; function. The articles fetched are being put into the &lt;code&gt;articles&lt;/code&gt; variable. In case of any error a message of &lt;code&gt;No articles found&lt;/code&gt; is put into the message variable.&lt;/p&gt;

&lt;p&gt;Below, in the return section, we are looping through all the fetched articles and showing the title of the article with a link to it and the name of the user who has posted the articles.&lt;/p&gt;

&lt;p&gt;Consequently, we will change the &lt;code&gt;src/App.css&lt;/code&gt; to have the following contents&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.App-header {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: calc(10px + 2vmin);
}

.App-header h2 {
  text-align: center;
}

.App-link {
  color: #61dafb;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CSS has been simplified to show the list of articles, removing the unneeded styles for the logo and the background. Text color and text alignment have been reset too.&lt;/p&gt;

&lt;p&gt;The focus of this tutorial is to help you learn how to do React feature flags with Flagsmith. When we run it with &lt;code&gt;yarn start&lt;/code&gt; after making the above changes, the application looks like below at this point:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7w9oaqux49ktw2w0ljz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7w9oaqux49ktw2w0ljz.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the scope of this guide, we will add the reading time in minutes for the articles. As this small feature will be added with JavaScript feature toggles, it will be very easy to turn it on and off simply by flipping a flag within Flagsmith; no re-deployments are necessary. That is the power and convenience of feature flags, as &lt;a href="https://flagsmith.com/blog/deployment-is-not-a-release/" rel="noopener noreferrer"&gt;deployment is not a release&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the next section, we will set up the feature flag for our example within Flagsmith’s UI. Then we will add Flagsmith’s JavaScript SDK, available on NPM, to our project. After that, we will add some code to implement the simple flag to show or hide the reading time for the Dev articles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Flagsmith to have Feature Flags
&lt;/h2&gt;

&lt;p&gt;Flagsmith is the open-source product - &lt;a href="https://ilya.today/ghfsdevtojavascript" rel="noopener noreferrer"&gt;check out Github&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;To create JavaScript feature toggles to show or hide the reading time for articles we will first create a project on Flagsmith. To create the project we will click the “Create Project” button after &lt;a href="https://app.flagsmith.com/signup?utm_source=devto&amp;amp;utm_medium=javascript" rel="noopener noreferrer"&gt;logging in&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7abhgfdlzsuyp8zo6bw7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7abhgfdlzsuyp8zo6bw7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have named the project Dev-React, and then, we will reach the project page like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft365vrhcklxghnrjyoe3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft365vrhcklxghnrjyoe3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will scroll down the page and create a new feature flag called &lt;code&gt;show_reading_time&lt;/code&gt; as seen below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8vrobywtmp6rbmbkqajs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8vrobywtmp6rbmbkqajs.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have created a new feature flag called &lt;code&gt;show_reading_time&lt;/code&gt; and enabled it. It would be created in both development and production environments in Flagsmith. Next, we will install the &lt;code&gt;flagsmith&lt;/code&gt; NPM library and use it in the React.js app for our JavaScript feature flags tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install and use Flagsmith JavaScript client
&lt;/h2&gt;

&lt;p&gt;If you like what we do, check out Flagsmith the open-source product - &lt;a href="https://ilya.today/ghfsdevtojavascript" rel="noopener noreferrer"&gt;check out Github&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;We have created the feature flag in Flagsmith on the UI, now it is time to use it in the Dev React app. To do this for our JavaScript feature flags tutorial, we will first get the Flagsmith JavaScript client from NPM running the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add flagsmith
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the &lt;code&gt;flagsmith&lt;/code&gt; client is installed we will change the code in &lt;code&gt;src/App.js&lt;/code&gt;. First, we will add the following line on line 2 to import Flagsmith library into the app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import flagsmith from 'flagsmith';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Subsequently, we will add the following at line 8 to initialize the &lt;code&gt;showReadingTime&lt;/code&gt; variable which will be false by default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [showReadingTime, setShowReadingTime] = useState(false);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we will add the code below in &lt;code&gt;useEffect&lt;/code&gt; function below &lt;code&gt;fetchArticles&lt;/code&gt; call at line 22 as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flagsmith.init({
    environmentID:"VKE5KnX8xXZuztTDGbcvBU",
    cacheFlags: true,
    enableAnalytics: true,
    onChange: (oldFlags, params) =&amp;gt; {
    setShowReadingTime(flagsmith.hasFeature('show_reading_time'));
    }
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can get the environment ID from the “Initialize your code” section of the feature flag page as seen below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyhtjzpjbgmkcy9qabmmb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyhtjzpjbgmkcy9qabmmb.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consequently add the following code where you see the looping through articles towards line 40:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul&amp;gt;
          {Array.isArray(articles) &amp;amp;&amp;amp; articles.map(
            article =&amp;gt; article.url &amp;amp;&amp;amp; &amp;lt;li&amp;gt;&amp;lt;a href={article.url} target="_blank" rel="noreferrer"&amp;gt;{article.title}&amp;lt;/a&amp;gt; – by {article.user.name} {showReadingTime ? '(Around ${article.reading_time_minutes} minute${article.reading_time_minutes &amp;gt; 1 ? "s": ""} read)' : ""}&amp;lt;/li&amp;gt;
          )}
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have first imported Flagsmith’s JavaScript client, then set the &lt;code&gt;showReadingTime&lt;/code&gt; on useEffect so that it is only called once on page load. Then when we render the articles we check if the reading time should be shown and then we print the reading time else we print the empty string. Next up we will see the changes in action.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test JavaScript feature toggles changes
&lt;/h2&gt;

&lt;p&gt;At this point if we again start the app it will show something like the below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsipepksditgvwr21kim7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsipepksditgvwr21kim7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great! We can see the reading time of the articles. Now if we would like to turn off showing the reading time, it is very easy. We can just go to the Flagsmith interface and turn the feature off like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flv2qq4yqkd2l0t9ar7ij.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flv2qq4yqkd2l0t9ar7ij.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After we hit “Confirm Changes” and the flag is off, if we come back and refresh the Dev React app page used for our example we will not see the reading times anymore as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcexzyuz3cp7zitw1rza5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcexzyuz3cp7zitw1rza5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wasn’t that easy? You can deploy the app and change the environment ID to be production for your production environment. In the next step, we will deploy the react application to Surge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy React App to Surge.sh (React Feature Flag)
&lt;/h2&gt;

&lt;p&gt;We have run the application locally, so to deploy it to a more production-like environment we will use Surge.sh. It is a very easy platform to deploy our front-end application. To deploy our React application to surge first we will replace the key from development to production one. To do this we will go to the “Production” environment and then click “Initialising your project” under the features section as seen below: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3meh25ukpobdtsse97p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3meh25ukpobdtsse97p.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We had done a similar thing for the development environment, as we want to deploy to a production-like environment we are replacing the environment ID to be of production. We will copy the environment id and replace it on line 23 of &lt;code&gt;src/App.js&lt;/code&gt; which will look like below after the change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flagsmith.init({
    environmentID:"BLPF23hJZ4ekaYV48epC55",
    cacheFlags: true,
    enableAnalytics: true,
    onChange: (oldFlags, params) =&amp;gt; {
     setShowReadingTime(flagsmith.hasFeature('show_reading_time'));
    }
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To deploy our Dev.to React app to surge we will run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will give the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvvvzk0i0myu0yngxnpl6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvvvzk0i0myu0yngxnpl6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will also create a &lt;code&gt;build&lt;/code&gt; folder with the output of the build process which has the index.html file and other static assets.&lt;/p&gt;

&lt;p&gt;To install the Surge command line we will run the following:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Consequently, we will go into the build folder and deploy the built app with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd build
surge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that type in your email and a password. Then it will find your current working directory as the project. Then if you want, change the subdomain, I have used &lt;code&gt;devto-react.surge.sh&lt;/code&gt; else use the random subdomain it provides. The hit enter and in a couple of seconds your app will be deployed to Surge over a CDN as seen below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ort7ltaw1hb3l8yoe3h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ort7ltaw1hb3l8yoe3h.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pretty neat! Below is how the app looks on Surge.sh with the toggle for reading time “on” for Javascript feature flag,  taken from the “production” environment:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbcyhyycotrwu1xrqimrp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbcyhyycotrwu1xrqimrp.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can try it out too at &lt;a href="https://devto-react.surge.sh" rel="noopener noreferrer"&gt;https://devto-react.surge.sh&lt;/a&gt;. You will get an email to verify your email address, if you are interested in Surge do check out their help section.  In the following part, we will look at the next steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;Implementing flags in JavaScript is a pretty easy task with amazing benefits. You can use the same Flagsmith JavaScript client in any frontend application ranging from vanilla JavaScript to Jquery to even Angular or Vue.js applications. It is also possible to use the SDK from a CDN with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/flagsmith/index.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The main concept here is to deploy the feature safely, if there is an issue we should be able to turn it off in seconds, not minutes or hours. That is easily possible with feature flags on an &lt;a href="https://flagsmith.com/open-source/" rel="noopener noreferrer"&gt;open-source platform&lt;/a&gt; like Flagsmith or with the &lt;a href="https://flagsmith.com/pricing/" rel="noopener noreferrer"&gt;free plan&lt;/a&gt;. The feature can be turned on and off with a couple of clicks, not with a deployment process. That adds unprecedented power and flexibility to the software engineering teams. The safety of feature release is another desirable by-product of the whole process. By the way, you definitely need to check &lt;a href="https://flagsmith.com/blog/best-practices-feature-flags/" rel="noopener noreferrer"&gt;5 best practices for Feature Flags&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We just saw how to implement JavaScript feature toggles on a simple React.js app that calls an API to show the latest Dev articles. This idea can be easily implemented in any frontend JavaScript application. Feature release can be done safely with high confidence and low time to turn on or off the released feature without the need to deploy any new code.&lt;/p&gt;

&lt;p&gt;P.S. the original article &lt;a href="https://flagsmith.com/blog/javascript-feature-flags/" rel="noopener noreferrer"&gt;was published here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to use Feature Flags in an iOS App [with code examples]</title>
      <dc:creator>Ilya Azovtsev</dc:creator>
      <pubDate>Wed, 02 Feb 2022 12:24:58 +0000</pubDate>
      <link>https://dev.to/ilya_azovtsev/how-to-use-feature-flags-in-an-ios-app-with-code-examples-511p</link>
      <guid>https://dev.to/ilya_azovtsev/how-to-use-feature-flags-in-an-ios-app-with-code-examples-511p</guid>
      <description>&lt;p&gt;If you ask yourself: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to test &amp;amp; deploy new features in your app without sending ap App Store update?&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;How to release your new version to only 1% (or 5%, or 50%) of the userbase?&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;You definitely need to read this article. Today we'll talk about Feature Flagging for IOS apps. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujcfjbc86ds07u94yfof.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujcfjbc86ds07u94yfof.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A feature flag helps you to enable or disable functionality remotely without deploying code. This is extremely helpful if you want to test and deploy new features without sending an App Store update. This enables you to decouple deployment from release, and you can experiment over the entire lifecycle of features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you should use Feature Flags (aka feature toggles) for IOS app
&lt;/h2&gt;

&lt;p&gt;Here is the list of main benefits:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Deploy features without risk&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even if something goes wrong, you can always rollback update easily. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Maintain release cycle easier&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even if some part of your code are unfinished, you still can release it and once everything ready just switch toggle and new feature will be in your app without sending an App Store update. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. A/B/n test &amp;amp; Canary deployment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With just feature flagging, you can release your new features &amp;amp; updates to only a group of people. It might be your beta testers who can use new updates in production or you can simply A/B/n test everything and check the impact on your metrics. &lt;/p&gt;

&lt;p&gt;This article will explore how to use the iOS feature flag. It contains the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creating Feature Flag on Flagsmith (&lt;a href="https://app.flagsmith.com/signup?utm_source=devto&amp;amp;utm_medium=iosapp" rel="noopener noreferrer"&gt;Sign up for free and use feature flags&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Installing the Flagsmith iOS SDK&lt;/li&gt;
&lt;li&gt;Working with the Flagsmith iOS SDK&lt;/li&gt;
&lt;li&gt;Testing the Feature Flag&lt;/li&gt;
&lt;li&gt;Testing Different Environments&lt;/li&gt;
&lt;li&gt;So let’s get started!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Getting Started with iOS Feature Flag
&lt;/h2&gt;

&lt;p&gt;Flagsmith has a sample project to showcase a demo feature flag, and &lt;a href="https://github.com/Flagsmith/sample-ios-app" rel="noopener noreferrer"&gt;you can download the starter project from here&lt;/a&gt;. This article assumes you know the basics of iOS development.&lt;/p&gt;

&lt;p&gt;Head over to Flagsmith and click Sign In on the top right corner. If you’re new to Flagsmith, you can start on the free trial:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9zqlienn8hcaxi8uqi5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9zqlienn8hcaxi8uqi5g.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can sign up via GitHub, Google or email:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fylisv2xfux324shxo1ww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fylisv2xfux324shxo1ww.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, create an organization to house all your projects:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd4unbrwzgb2xsozxjsa9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd4unbrwzgb2xsozxjsa9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating the organization, create the project that will contain the iOS feature flag. When you create a project, Flagsmith also generates a development and production environment for you. You can create features for your project, then enable and configure them per environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fku0blsla3zkruv7conil.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fku0blsla3zkruv7conil.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll be redirected to your project’s homepage that will contain all the information about your features:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd9cgmzbwa578buxr6si5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd9cgmzbwa578buxr6si5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that you’ve set up the project, it’s time to create your first feature flag!&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Feature Flag on Flagsmith
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://app.flagsmith.com/signup?utm_source=devto&amp;amp;utm_medium=iosapp" rel="noopener noreferrer"&gt;&amp;gt;&amp;gt;Sing up for free and use feature flags!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create your first feature, head over to the &lt;strong&gt;Features tab&lt;/strong&gt; from the sidebar. You’ll be taken to the &lt;strong&gt;Features main page&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtgceqf4l7hg5a38bal7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtgceqf4l7hg5a38bal7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are two types of features that you can create for your project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feature Flags:&lt;/strong&gt; This allows you to toggle features on and off. For example, a messaging feature on your app that you only want to show and test in Development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Remote configuration:&lt;/strong&gt; This allows you to provide configuration for a particular feature. For example, anything from font size for a website/mobile app or an environment variable for a server.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, we’ll focus on adding a feature flag. Every feature comes with two default environments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Development&lt;/li&gt;
&lt;li&gt;Production&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you create a new feature, Flagsmith makes copies of it for each environment, allowing you to edit the values in the feature separately. Also, you can create more environments if you want.&lt;/p&gt;

&lt;p&gt;The Flagsmith SDK also provides you with the ability to &lt;strong&gt;identify&lt;/strong&gt; your user when they log in to your app. It adds them to the user’s page. You can then configure the features per user. For example, while working on a new messaging feature, you can show it to only a particular identified user or set of users.&lt;/p&gt;

&lt;p&gt;On the Features page, click on the &lt;strong&gt;Create Your First Feature button&lt;/strong&gt;. It slides a &lt;strong&gt;New Feature page&lt;/strong&gt;, where you can fill in the details:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8q1ei4zru50qpsfma96y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8q1ei4zru50qpsfma96y.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are five options for every feature:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ID&lt;/strong&gt;: Name of the feature. For example, header_size.&lt;/li&gt;
&lt;li&gt;Enabled by default: A switch to enable the feature by default.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Value&lt;/strong&gt;: providing an optional value with the feature in the form of &lt;em&gt;.txt, .json, .xml, toml and .yaml&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Provide an optional note that explains the feature. For example, “This determines what size the header is”.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Archived&lt;/strong&gt;: A switch to archive a feature. It helps you filter a feature from the Flagsmith dashboard to determine the ones that are not relevant anymore.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, you can name the ID as show_onboarding for a feature flag to enable the onboarding screen. It will be disabled by default. Let’s leave the Value field empty as it will act as a feature flag with only a boolean value. Then, add the description as This enables the onboarding screen. As you’re going to use it, leave the &lt;strong&gt;Archived&lt;/strong&gt; option off.&lt;/p&gt;

&lt;p&gt;Note that this creates the feature for all environments, and you can edit this feature for every environment after the feature is created.&lt;/p&gt;

&lt;p&gt;After you’re done filling in the information, click the &lt;strong&gt;Create Feature&lt;/strong&gt; button. And that’s it, you’ve created your first feature flag within a few minutes!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the Flagsmith iOS SDK
&lt;/h2&gt;

&lt;p&gt;Flagsmith iOS SDK can be installed via two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CocoaPods&lt;/li&gt;
&lt;li&gt;Swift Package Manager (SPM)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install via CocoaPods, add the following line to your pod file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pod 'FlagsmithClient', '~&amp;gt; 1.0.1'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install via SPM, add the following to your Package.swift file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies: [
    .package(url: "https://github.com/Flagsmith/flagsmith-ios-client.git", from: "1.1.1"),
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your project doesn’t contain a &lt;code&gt;Package.swift&lt;/code&gt; file, go to the Menu bar in Xcode, select &lt;strong&gt;File&lt;/strong&gt;, and then &lt;strong&gt;Add Packages&lt;/strong&gt;. Then, in the search field, add the following URL:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Flagsmith/flagsmith-ios-client.git" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Next&lt;/strong&gt;. The current version at the time of writing is 1.1.1. Click &lt;strong&gt;Next&lt;/strong&gt; again and then checkmark the SDK to add to your project’s target. Finally, click &lt;strong&gt;Finish&lt;/strong&gt; to add the iOS SDK to your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with the Flagsmith iOS SDK
&lt;/h2&gt;

&lt;p&gt;If you’re using AppDelegate, you can initialize the SDK in application(_:didFinishLaunchingWithOptions:) method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import FlagsmithClient
func application(_ application: UIApplication,
 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&amp;gt; Bool {
  Flagsmith.shared.apiKey = "&amp;lt;#YOUR API KEY#&amp;gt;"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you’re using SwiftUI’s new lifecycle, it can be initialized by setting the API key inside the init() method in the App. In the sample project, it can be initialized as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import FlagsmithClient
extension FlagsmithExampleApp {
  private func initializeFlagsmith() {
    Flagsmith.shared.apiKey = "&amp;lt;#YOUR API KEY#&amp;gt;"
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, in the FlagsmithExampleApp struct, you call this method in the init():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@main
struct FlagsmithExampleApp: App {
  init() {
    initializeFlagsmith()
  }
  var body: some Scene {
    WindowGroup {
      MainView()
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By setting up your API key and initializing the SDK at launch, you can fetch the feature flags from Flagsmith.&lt;/p&gt;

&lt;p&gt;The SDK offers two methods to retrieve the flags – you can either fetch all the flags or retrieve the flag by its name.&lt;/p&gt;

&lt;p&gt;For the former one, you then loop over the flags and save them accordingly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flagsmith.shared.getFeatureFlags() { (result) in
    switch result {
    case .success(let flags):
        for flag in flags {
            let name = flag.feature.name
            let value = flag.value?.stringValue
            let enabled = flag.enabled
            print(name, "= enabled:", enabled, "value:", value ?? "nil")
        }
    case .failure(let error):
        print(error)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the sample project, you can create an enum for the feature flags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum FeatureFlags: String {
  case showOnboarding = "show_onboarding"
  var id: String {
    self.rawValue
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the case to get the desired feature flag. Then, put this piece of code in the initialization method to retrieve the flags at launch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private func initializeFlagsmith() {
  Flagsmith.shared.apiKey = "&amp;lt;#YOUR API KEY#&amp;gt;"
  Flagsmith.shared.getFeatureFlags { (result) in
    switch result {
      case .success(let flags):
        for flag in flags {
          // Comparing the feature flag's name to the particular ID.
          if flag.feature.name == FeatureFlags.showOnboarding.id {
            DispatchQueue.main.async {
              viewModel.showOnboarding = flag.enabled
            }
          }
        }
      case .failure(let error):
        print(error)
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can search for feature flag by its name. It returns a Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flagsmith.shared
  .hasFeatureFlag(withID: FeatureFlags.showOnboarding.id, forIdentity: nil) { (result) in
  switch result {
    case .success(let value):
      DispatchQueue.main.async {
        viewModel.showOnboarding = value
     }
    case .failure(let error):
      print(error)
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the beginning, the value of the flag show_onboarding was set to false by default. Run the app, and you’ll see that it opens to the main screen instead of the onboarding screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2f24r75d4u9lh40k6ms9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2f24r75d4u9lh40k6ms9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next section, you’re going to test the feature by toggling the value of the feature flag and running the app accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the iOS Feature Flag
&lt;/h2&gt;

&lt;p&gt;Go to the Flagsmith project and toggle the feature flag show_onboarding by switching the &lt;strong&gt;OFF ** button to **ON&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qny4m054sc6gu2douky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qny4m054sc6gu2douky.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will show an alert that will turn show onboarding “On” for &lt;strong&gt;Development&lt;/strong&gt;. Click on &lt;strong&gt;Confirm Changes&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fekiqf7p13d50dy82qsla.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fekiqf7p13d50dy82qsla.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ve successfully changed the value of the feature flag.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flzl49yqsjtwlkdn0pz0c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flzl49yqsjtwlkdn0pz0c.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, head over to Xcode, and rerun the project. You’ll see that the onboarding screen is being displayed as the first screen!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sqdv9giqmbfcnlrvmix.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sqdv9giqmbfcnlrvmix.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Different Environments
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://app.flagsmith.com/signup?utm_source=devto&amp;amp;utm_medium=iosapp" rel="noopener noreferrer"&gt;&amp;gt;&amp;gt;Sign up for free and use feature flags!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flagsmith also provides you with different environments per feature. You can find the different environment on the main page of the project:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F18a3srpmri2kuqivmujl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F18a3srpmri2kuqivmujl.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each environment has its own specific API key. So, from the sidebar, select Settings under the Production heading and copy the API key from here. show_onboarding is disabled by default in Production, while in the previous section, you enabled it in Development.&lt;/p&gt;

&lt;p&gt;To differentiate between the two, go back to Xcode and FlagsmithExampleApp.swift. Replace the following code where you set the API key with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#if DEBUG
    Flagsmith.shared.apiKey = "&amp;lt;#YOUR DEVELOPMENT API KEY#&amp;gt;"
 #else
    Flagsmith.shared.apiKey = "&amp;lt;#YOUR PRODUCTION API KEY#&amp;gt;"
 #endif 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, click on the current scheme and then edit the scheme:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxx099dku94c5uz7lth3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxx099dku94c5uz7lth3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the sidebar, select &lt;strong&gt;Run&lt;/strong&gt;. Under the &lt;strong&gt;Info&lt;/strong&gt; tab, change the build configuration to &lt;strong&gt;Release&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftw3g8pvu1qfk8squbob3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftw3g8pvu1qfk8squbob3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run the app, and you’ll see that the onboarding is disabled!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgnyxr8c6fn465zq96ly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgnyxr8c6fn465zq96ly.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you run the app in &lt;strong&gt;Debug&lt;/strong&gt; configuration, you will see the onboarding screen again. You can create a custom build configuration on &lt;strong&gt;Xcode&lt;/strong&gt; as well. For example, you can create an Environment &lt;strong&gt;Test Flight&lt;/strong&gt; in Flagsmith and create a similar one in Xcode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You &lt;a href="https://github.com/Flagsmith/sample-ios-app" rel="noopener noreferrer"&gt;can download the final project from here&lt;/a&gt;. Using Flagsmith, you can release features with confidence and manage feature flags across web, mobile, and server-side applications.&lt;/p&gt;

&lt;p&gt;This article helps you get started with using Feature Flags in your iOS app so that you have more control over your features without worrying about sending updates. You can use the best &lt;a href="https://flagsmith.com/open-source/" rel="noopener noreferrer"&gt;open-source feature flag&lt;/a&gt; for your next Xcode project. Flagsmith also has &lt;a href="https://flagsmith.com/on-premises-and-private-cloud-hosting/" rel="noopener noreferrer"&gt;on-premises&lt;/a&gt; and &lt;a href="https://flagsmith.com/cloud/" rel="noopener noreferrer"&gt;cloud-hosted&lt;/a&gt; solutions with great pricing plans.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://app.flagsmith.com/signup?utm_source=devto&amp;amp;utm_medium=iosapp" rel="noopener noreferrer"&gt;&amp;gt;&amp;gt;Sign up for free and use feature flags!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flagsmith also offers a more robust feature called Remote Configuration, where you can send the values over the feature and retrieve them in your app. You can learn more about Remote Config in this post.&lt;/p&gt;

&lt;p&gt;Do let us know if you’ve any suggestions/feedback!  &lt;/p&gt;

&lt;p&gt;Btw, &lt;a href="https://flagsmith.com/blog/feature-flags-in-an-ios-app/" rel="noopener noreferrer"&gt;the original article was posted here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
