Skip to content

Card component injects invalid props into React.Fragment children #4710

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

Open
adolfogc opened this issue May 1, 2025 · 0 comments
Open

Card component injects invalid props into React.Fragment children #4710

adolfogc opened this issue May 1, 2025 · 0 comments

Comments

@adolfogc
Copy link

adolfogc commented May 1, 2025

Current behaviour

The Card component clones its children and injects additional props (index, total, siblings, borderRadiusStyles). This leads to runtime errors when a child is a React.Fragment, which only accepts key and children props. Other components that do not expect these props may also be affected.

Image

Expected behaviour

The Card component should render React.Fragment children without throwing runtime errors by avoiding invalid prop injection.

How to reproduce?

Pass a React.Fragment as a child of Card.

What have you tried so far?

Relevant source line: https://github.com/callstack/react-native-paper/blob/main/src/components/Card/Card.tsx#L278

Potential fix:

  import { Fragment } from 'react';
  
  // ...

  const content = (
    <View style={[styles.innerContainer, contentStyle]} testID={testID}>
      {React.Children.map(children, (child, index) => {
        if (!React.isValidElement(child)) {
          return child;
        }
        if (child.type === Fragment) {
          return child;
        }

        return React.cloneElement(child as React.ReactElement<any>, {
          index,
          total,
          siblings,
          borderRadiusStyles,
        });
      })}
    </View>
  );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants