Skip to content

Commit 22ce19f

Browse files
committed
Add checks + update type to allow props.value to be null | undefined
1 parent 1236d1f commit 22ce19f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/ReactCodeInput.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface ReactCodeInputProps {
2121
placeholder?: string
2222

2323
// Value of the input
24-
value?: string
24+
value?: string | null
2525

2626
// Get the full value of the input on every change
2727
onChange?: (value: string) => void

src/ReactCodeInput.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ReactCodeInput extends Component {
3333
super(props);
3434

3535
const { fields, forceUppercase } = props;
36-
let { value } = props;
36+
let value = props.value || '';
3737

3838
if (forceUppercase) {
3939
value = value.toUpperCase();
@@ -55,6 +55,10 @@ class ReactCodeInput extends Component {
5555
}
5656

5757
UNSAFE_componentWillReceiveProps(nextProps) {
58+
if (nextProps.value == null) {
59+
return;
60+
}
61+
5862
this.setState({
5963
value: nextProps.value,
6064
});

0 commit comments

Comments
 (0)