Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit addb02b

Browse files
committed
ref: incorporated dynamic library import
1 parent 4d35146 commit addb02b

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/components/core/text-field/text-field.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import zxcvbn from 'zxcvbn';
2-
import { forwardRef, Fragment, InputHTMLAttributes, ReactNode, useState } from 'react';
1+
import { forwardRef, Fragment, InputHTMLAttributes, ReactNode, useState, useRef, useEffect } from 'react';
32
import { styled } from 'Styles/stitches.config';
43

54
type InputTypes = 'text' | 'number' | 'email' | 'password' | 'tel' | 'textarea';
@@ -35,7 +34,20 @@ const StyledPasswordMeter = styled(StyledPasswordMeterWrapper, {
3534
transition: 'width 0.25s ease-in-out',
3635
});
3736
const PasswordStrengthMeter = ({ user_input, disable_meter, dark }: TPasswordStrengthProps) => {
38-
const test_result: zxcvbn.ZXCVBNResult = zxcvbn(user_input);
37+
const zxcvbn = useRef<any>();
38+
let test_result = { score: 0 };
39+
40+
useEffect(() => {
41+
async function loadLibrary() {
42+
const { default: lib } = await import('zxcvbn');
43+
zxcvbn.current = lib;
44+
}
45+
loadLibrary();
46+
}, []);
47+
48+
if (typeof zxcvbn.current === 'function') {
49+
test_result = zxcvbn.current(user_input);
50+
}
3951
const score: number = (test_result.score * 100) / 4;
4052
const meter_color: any = Object.freeze({
4153
0: dark ? '$greyDark500' : '$greyLight300',

0 commit comments

Comments
 (0)