Skip to content

defaultProps are not set in the react native 0.79.5 and react 19.0.0, expo 53.0.0. You get the error: "TypeError: Cannot read property 'one' of undefined". It's because defaultProps is deprecated in react. #4

Description

@patchuko

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-numeric-pad@1.1.5 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-numeric-pad/index.js b/node_modules/react-native-numeric-pad/index.js
index 4aad529..a53177f 100644
--- a/node_modules/react-native-numeric-pad/index.js
+++ b/node_modules/react-native-numeric-pad/index.js
@@ -40,9 +40,44 @@ const ViewHolder = () => {
   return <View style={NumpadStyle.buttonContainer} />
 }
 
+const defaultProps = {
+  buttonTextByKey: {
+    one: '1',
+    two: '2',
+    three: '3',
+    four: '4',
+    five: '5',
+    six: '6',
+    seven: '7',
+    eight: '8',
+    nine: '9',
+    dot: '.',
+    zero: '0'
+  },
+  accessible: false,
+  onButtonPress: () => {},
+  onRightButtonPress: () => {},
+  style: { paddingVertical: 12 },
+  activeOpacity: 0.9,
+  buttonTextStyle: { color: '#000', fontSize: 30, fontWeight: '400' },
+  rightBottomAccessibilityLabel: 'right_bottom',
+  numericDisabled: false,
+  rightBottomButtonDisabled: false,
+  allowDecimal: true
+}
+
 const NumericPad = React.forwardRef(
   (
-    {
+    props,
+    ref
+  ) => {
+    //Default props
+    const propsWithDefaults = {
+      ...defaultProps,
+      ...props,
+    }
+ 
+    const {
       numLength,
       allowDecimal,
       onValueChange,
@@ -61,9 +96,9 @@ const NumericPad = React.forwardRef(
       rightBottomAccessibilityLabel,
       rightBottomButtonItemStyle,
       onRightBottomButtonPress
-    },
-    ref
-  ) => {
+    } = propsWithDefaults;
+
+
     const [input, setInput] = useState('')
     ref.current = {
       clear: () => {
@@ -232,31 +267,7 @@ const NumericPad = React.forwardRef(
   }
 )
 
-NumericPad.defaultProps = {
-  buttonTextByKey: {
-    one: '1',
-    two: '2',
-    three: '3',
-    four: '4',
-    five: '5',
-    six: '6',
-    seven: '7',
-    eight: '8',
-    nine: '9',
-    dot: '.',
-    zero: '0'
-  },
-  accessible: false,
-  onButtonPress: () => {},
-  onRightButtonPress: () => {},
-  style: { paddingVertical: 12 },
-  activeOpacity: 0.9,
-  buttonTextStyle: { color: '#000', fontSize: 30, fontWeight: '400' },
-  rightBottomAccessibilityLabel: 'right_bottom',
-  numericDisabled: false,
-  rightBottomButtonDisabled: false,
-  allowDecimal: true
-}
+
 
 const NumpadStyle = StyleSheet.create({
   container: {

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions