<?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: chuluq</title>
    <description>The latest articles on DEV Community by chuluq (@chuluq).</description>
    <link>https://dev.to/chuluq</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%2F511271%2F5316e390-0f14-4be8-b513-79fc38339fdf.jpeg</url>
      <title>DEV Community: chuluq</title>
      <link>https://dev.to/chuluq</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chuluq"/>
    <language>en</language>
    <item>
      <title>How to Prevent Save Password Prompt of Browser</title>
      <dc:creator>chuluq</dc:creator>
      <pubDate>Mon, 19 Jun 2023 06:39:17 +0000</pubDate>
      <link>https://dev.to/chuluq/how-to-prevent-save-password-prompt-of-browser-40hg</link>
      <guid>https://dev.to/chuluq/how-to-prevent-save-password-prompt-of-browser-40hg</guid>
      <description>&lt;p&gt;Nowadays, almost every browser has functionality to save password whenever user input password form. It used to enhance user experience so that user doesn't need to remember their password.&lt;/p&gt;

&lt;p&gt;However, in some cases such as company that has secured information, it leaks security vulnerability for them. So in this post, I'm going to show you how to prevent that dialog to pop-up.&lt;/p&gt;

&lt;p&gt;Let's say you have password input that looks like this, &lt;code&gt;App.tsx&lt;/code&gt;.&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;input
  type="password"
  name="password"
  value={password}
  onChange={(e) =&amp;gt; setPassword(e.target.value)}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to prevent password save prompt to pop-up, you just need to change input type into free-text, then put a line of CSS to change text into bullets. It is going to look 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;&amp;lt;input
  type="text"
  name="password"
  autoComplete="off"
  value={password}
  onChange={(e) =&amp;gt; setPassword(e.target.value)}
  className="txtPassword"
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.txtPassword {
  -webkit-text-security: disc;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I add auto-complete to off in order to prevent browser to remember field that we fill in.&lt;/p&gt;

&lt;p&gt;That's all, thank you for reading this post. Hope this post helps your problem.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How I Create Simple Counter App yet Elegant</title>
      <dc:creator>chuluq</dc:creator>
      <pubDate>Mon, 08 Mar 2021 01:23:12 +0000</pubDate>
      <link>https://dev.to/chuluq/how-i-create-simple-counter-app-yet-elegant-3bgh</link>
      <guid>https://dev.to/chuluq/how-i-create-simple-counter-app-yet-elegant-3bgh</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://reactnative.dev"&gt;React Native&lt;/a&gt; is react framework to build native app (ios or android). To create this project you could either use React Native or Expo &lt;a href="https://reactnative.dev/docs/environment-setup"&gt;see details&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisite
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;Hooks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I assume you already knew basic react and hooks so I am not going to tell you every details. If you pass this, you are good to go to follow this tutorial.&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's Start
&lt;/h1&gt;

&lt;p&gt;I am going to use React Native to create a new app.&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 counter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need to run this in terminal. &lt;em&gt;npx&lt;/em&gt; allows you to create react-native without install react-native globally.&lt;/p&gt;

&lt;p&gt;Ok! next, open the project in vs code or any editor that you like. Run project using &lt;code&gt;yarn start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since I used react native command, I need to use simulator or connect my phone in order to see the result &lt;a href="https://reactnative.dev/docs/environment-setup"&gt;see details&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this tutorial, we should focus only at app.js, since we don't have many screens. Delete all code inside it or rewrite it with below code.&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 from 'react';
import {View, Text} from 'react-native';

const App = () =&amp;gt; {
  return (
    &amp;lt;View&amp;gt;
      &amp;lt;Text&amp;gt;React Native&amp;lt;/Text&amp;gt;
    &amp;lt;/View&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;You should see 'React Native' text in your screen.&lt;/p&gt;

&lt;p&gt;Next, we are going to use &lt;code&gt;useState&lt;/code&gt; to manage our number state. How to do it? Simple, just declare variable to store state. I am going to call it number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [number, setNumber] = useState(0);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;setNumber&lt;/code&gt; here is common way to setState which is combination of 'set' + 'state' variable.&lt;/p&gt;

&lt;p&gt;Then, we need to make whole screen to be touchable. To do this, we simply overwrite &lt;code&gt;View&lt;/code&gt; tag with &lt;code&gt;TouchableOpacity&lt;/code&gt; from react-native. Don't forget to import that from react-native. Next, pass number state inside &lt;code&gt;Text&lt;/code&gt; tag. Now your code should be 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;&amp;lt;TouchableOpacity&amp;gt;
  &amp;lt;Text&amp;gt;
    {number}
  &amp;lt;/Text&amp;gt;
&amp;lt;/TouchableOpacity&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Handle State
&lt;/h1&gt;

&lt;p&gt;Now, we need to to handle change of state so then we can increment the number. Pass &lt;code&gt;onPress&lt;/code&gt; event inside TouchableOpacity tag &lt;code&gt;&amp;lt;TouchableOpacity onPress={handlePress}&amp;gt;&lt;/code&gt;. Create &lt;code&gt;handlePress&lt;/code&gt; to &lt;code&gt;setNumber(number + 1)&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handlePress = () =&amp;gt; {
  setNumber(number + 1);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can style number as you wish, to me I just center the number. My code is look like this now.&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 {
  Text,
  StyleSheet,
  TouchableOpacity
} from 'react-native';

const App = () =&amp;gt; {
  const [number, setNumber] = useState(0);

  const handlePress = () =&amp;gt; {
    setNumber(number + 1);
  };

  return (
    &amp;lt;TouchableOpacity
      style={styles.container}
      activeOpacity={1}
      onPress={handlePress}&amp;gt;
      &amp;lt;Text style={styles.number}&amp;gt;
        {number}
      &amp;lt;/Text&amp;gt;
    &amp;lt;/TouchableOpacity&amp;gt;
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  number: {
    fontSize: 96,
  }
});

export default App;

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

&lt;/div&gt;



&lt;p&gt;There is a time when the application doesn't refresh automatically, when this is happen you might just need to stop the app and bundle app again.&lt;/p&gt;

&lt;h1&gt;
  
  
  Back Button to Reset State
&lt;/h1&gt;

&lt;p&gt;Since we've done handle state, we need to find a way how to reset state of number to be zero. There are a lot of ways to accomplish this, I will choose back button in smartphone to reset state.&lt;/p&gt;

&lt;p&gt;We need to import &lt;code&gt;Backhandler&lt;/code&gt; from react native. To listen this backhandler we need to use &lt;code&gt;useEffect&lt;/code&gt;. However, this &lt;code&gt;Backhandler&lt;/code&gt; only can use in Android device only. You can see details of this &lt;a href="https://reactnative.dev/docs/backhandler"&gt;backhandler&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
  const backAction = () =&amp;gt; {
    if (number !== 0) {
      setNumber(0);
      BackHandler.removeEventListener();
    } else {
      BackHandler.exitApp();
    }

    return true;
  };

  const backHandler = BackHandler.addEventListener(
   'hardwareBackPress',
    backAction,
  );

  return () =&amp;gt; backHandler.remove();
}, [number]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever back button is pressed, app will check whether number is zero or not. If number is zero then it will exit the app, if number is not zero, then it will reset number to zero. I add &lt;code&gt;[number]&lt;/code&gt; dependency so this function will run whenever number state changes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/14sy6VGAd4BdKM/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img width="50%" src="https://i.giphy.com/media/14sy6VGAd4BdKM/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well done, you've completed this main function. However, I will add change theme so this app will look a bit better.&lt;/p&gt;

&lt;h1&gt;
  
  
  Switch Theme
&lt;/h1&gt;

&lt;p&gt;We need to import &lt;code&gt;Switch&lt;/code&gt; from react native. Then add that into your app. You can see details &lt;a href="https://reactnative.dev/docs/switch"&gt;here&lt;/a&gt;.&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;Switch
 trackColor={{false: '#767577', true: '#3BBACB'}}
 thumbColor={isEnabled ? '#151A23' : '#F3F4F6'}
 onValueChange={toggleSwitch}
 value={isEnabled}
 style={styles.switch}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To track the switch, we use &lt;code&gt;useState&lt;/code&gt;. Simply &lt;code&gt;const [isEnabled, setIsEnabled] = useState(false);&lt;/code&gt; and &lt;code&gt;const toggleSwitch = () =&amp;gt; setIsEnabled(!isEnabled);&lt;/code&gt;. We also need to pass background color inside TouchableOpacity. Now our code should be 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;&amp;lt;TouchableOpacity
  style={[
   styles.container,
     {backgroundColor: isEnabled ? '#56CCF2' : '#151A23'},
   ]}
   activeOpacity={1}
   onPress={handlePress}&amp;gt;
   &amp;lt;Text style={[styles.number, {color: isEnabled ? '#151A23' : '#F3F4F6'}]}&amp;gt;
     {number}
   &amp;lt;/Text&amp;gt;
   &amp;lt;Switch
      trackColor={{false: '#767577', true: '#3BBACB'}}
      thumbColor={isEnabled ? '#151A23' : '#F3F4F6'}
      onValueChange={toggleSwitch}
      value={isEnabled}
      style={styles.switch}
    /&amp;gt;
&amp;lt;/TouchableOpacity&amp;gt;

...
switch: {
  position: 'absolute',
  bottom: 0,
  marginBottom: 32,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for follow along this tutorial, you can find full code &lt;a href="https://github.com/chuluq/counter"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
