Skip to content

Children type should be ReactNode instead of ReactElement #268

Open

Description

The type of the children prop in FlagsmithContextType doesn't align with the type normally used for children props which results in having to wrap an actual children prop used inside a FlagsmithProvider with a fragment to make it work without TS errors. Perhaps the type could be changed from ReactElement | ReactElement[] to simply ReactNode, which would be the same as the PropsWithChildren generic type provided by React.

// Example of error
type FeatureFlagProviderType = {
  serverState: IState;
};

export const FeatureFlagProvider = ({
  serverState,
  children, // ReactNode
}: PropsWithChildren<FeatureFlagProviderType>) => {
  const flagsmithInstance = useRef(createFlagsmithInstance());
  return (
    <FlagsmithProvider
      flagsmith={flagsmithInstance.current}
      serverState={serverState}
    >
      {children}
    </FlagsmithProvider>
  );
};

However, by wrapping children with a fragment or something else, there are no issues.

Perhaps I'm missing something, but is there any special reasoning behind using ReactElement | ReactElement[] for children?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions