Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Props containing "key" prop is being spread into JSX #4562

Open
ChromeQ opened this issue Nov 25, 2024 · 1 comment · May be fixed by #4563
Open

Warning: Props containing "key" prop is being spread into JSX #4562

ChromeQ opened this issue Nov 25, 2024 · 1 comment · May be fixed by #4563

Comments

@ChromeQ
Copy link

ChromeQ commented Nov 25, 2024

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Recently upgraded an expo project to Expo SDK 52 which includes react-native 0.76, the following warning/error is being thrown when rendering a BottomNavigationBar:

 ERROR  Warning: A props object containing a "key" prop is being spread into JSX:
  let props = {key: someKey, route: ..., borderless: ..., centered: ..., rippleColor: ..., onPress: ..., onLongPress: ..., testID: ..., accessibilityLabel: ..., accessibilityRole: ..., accessibilityState: ..., style: ..., children: ...};
  <Touchable {...props} />
React keys must be passed directly to JSX without using spread:
  let props = {route: ..., borderless: ..., centered: ..., rippleColor: ..., onPress: ..., onLongPress: ..., testID: ..., accessibilityLabel: ..., accessibilityRole: ..., accessibilityState: ..., style: ..., children: ...};
  <Touchable key={someKey} {...props} />
    in BottomNavigation.Bar (created by BottomNavigation)
    in RCTView (created by View)
    in View (created by BottomNavigation)
    in BottomNavigation (created by MaterialBottomTabView)
    in MaterialBottomTabView (created by MaterialBottomTabNavigator)
    in PreventRemoveProvider (created by NavigationContent)
    in NavigationContent
    in Unknown (created by MaterialBottomTabNavigator)
    in MaterialBottomTabNavigator (created by MemoHomeScreen)

The stack trace is much longer but I stopped at MemoHomeScreen as that is the first of my own files.
I delved into the source code and found the following which the diff that solved my problem:

diff --git a/node_modules/react-native-paper/src/components/BottomNavigation/BottomNavigationBar.tsx b/node_modules/react-native-paper/src/components/BottomNavigation/BottomNavigationBar.tsx
index 0bfe303..a59ae06 100644
--- a/node_modules/react-native-paper/src/components/BottomNavigation/BottomNavigationBar.tsx
+++ b/node_modules/react-native-paper/src/components/BottomNavigation/BottomNavigationBar.tsx
@@ -360,7 +360,7 @@ const BottomNavigationBar = <Route extends BaseRoute>({
   navigationState,
   renderIcon,
   renderLabel,
-  renderTouchable = (props: TouchableProps<Route>) => <Touchable {...props} />,
+  renderTouchable = ({ key, ...props }: TouchableProps<Route>) => <Touchable key={key} {...props} />,
   getLabelText = ({ route }: { route: Route }) => route.title,
   getBadge = ({ route }: { route: Route }) => route.badge,
   getColor = ({ route }: { route: Route }) => route.color,

This issue body was partially generated by patch-package.

P.S. This diff only changes the source file, the .js file in node_modules/react-native-paper/lib/module/components/BottomNavigation/BottomNavigationBar.js will also need changing if patching yourself, something like:

-    renderTouchable = props => /*#__PURE__*/React.createElement(Touchable, props),
+    renderTouchable = ({
+      key,
+      ...props
+    }) => /*#__PURE__*/React.createElement(Touchable, _extends({
+      key: key
+    }, props)),
@ChromeQ
Copy link
Author

ChromeQ commented Nov 25, 2024

Just realised this is a duplicate of
#4503
#4494
#4401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant