Skip to content

fix(Button): narrow ButtonProps children to ReactNode#4033

Open
patrickwehbe wants to merge 1 commit into
react-native-elements:nextfrom
patrickwehbe:fix/button-children-react19-type
Open

fix(Button): narrow ButtonProps children to ReactNode#4033
patrickwehbe wants to merge 1 commit into
react-native-elements:nextfrom
patrickwehbe:fix/button-children-react19-type

Conversation

@patrickwehbe

Copy link
Copy Markdown

Motivation

ButtonProps extends PressableProps, which types children as ReactNode | ((state: PressableStateCallbackType) => ReactNode). Since React 18, @types/react no longer accepts function children as a ReactNode in JSX, so any wrapper that spreads ButtonProps via {...rest} into <Button /> fails to type-check:

Type '(state: PressableStateCallbackType) => ReactNode' is not assignable to type 'ReactNode'
import { Button as RNEButton, type ButtonProps } from '@rneui/themed';

const Button = ({ ...rest }: ButtonProps) => {
  return <RNEButton {...rest} />; // TS2322 under @types/react 19
};

The Button component never uses the render-prop form of children. It defaults children to title and renders whatever it gets through React.Children.toArray, so the function variant is dead from the public API's point of view. Narrowing children to ReactNode on ButtonProps drops the variant the component doesn't support and lets these wrappers compile again.

This is a type-only change, no runtime behavior changes.

Fixes #4032

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Reproduced the error first, then confirmed the fix, with the versions already pinned in the repo (TypeScript 5.9, @types/react 19). A wrapper that does <Button {...rest} /> reports TS2322 on next and type-checks clean with this change. yarn typescript passes.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

ButtonProps extends PressableProps, whose children type under
@types/react 19 is ReactNode | ((state: PressableStateCallbackType) => ReactNode).
React 18+ no longer accepts function children as ReactNode in JSX, so any
wrapper that spreads ButtonProps via {...rest} into <Button /> fails to
type-check with TS2322.

The Button component only ever renders children as nodes (it defaults
children to title and runs them through React.Children.toArray); it never
calls the render-prop form. Declaring children?: ReactNode on ButtonProps
narrows the inherited type to what the component actually supports.

Closes react-native-elements#4032
@theianmay
theianmay self-requested a review June 21, 2026 16:59
@theianmay theianmay self-assigned this Jun 21, 2026
@theianmay theianmay added the component: Button Issue related to Button Component label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: Button Issue related to Button Component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ButtonProps children type incompatible with React 19+ JSX ((state: PressableStateCallbackType) => ReactNode not assignable to ReactNode)

2 participants