React Native hide show password input

Md Moin
2 min readDec 29, 2018

--

I’m here to share with you today another native implementation of a common problem, if you work with react native you know that it’s a library that does not provide you every feature to build an application which makes it flexible as well in terms of using it. But quite often we notice people often relying on libraries to achieve even the smallest of tasks, something like hiding & showing password on click of an icon. In react i firmly believe that try to achieve things natively & logically if not you can seek out a library for help. Today we are going to make something as below

React native hide show password

I was looking for something similar like every other developer & i did find a library but than i gave it a thought & looked out on the support that library has offered hasn’t been great. Why, rely on them when you can make your own & i came up with an implementation of my own as below.

React native hide show password component

Here we have a PasswordTextBox component which helps us in achieving the above results. I have used native base for UI but it does not matter which UI framework you are using, its more off a conceptual thing in this. You can follow the below steps to achieve this using any UI library including react-native itself

  1. Declare a state with default icon & to hide/show password
  2. Render the icon with the state & text box in password mode on load
  3. On icon tap, trigger the event to update the state of text & icon

You can use the component as below

<PasswordTextBox icon=”lock” label=”New Password” onChange={(v) => this._updateState(‘new’, v)} />

--

--

Md Moin
Md Moin

Written by Md Moin

I’m a dev who codes for fun & likes to share my learnings.

Responses (2)