Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & ReactNode'

Got this error here:

Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & ReactNode'.

export const withAppProvider = (Component: AppComponent) => {
  return function WrapperComponent(props: any) {
    return (
      <AppProvider> // <-- here
        <Component {...props} />
      </AppProvider>
    );
  };
};

Maybe something wrong with AppProvider declaration?

export const AppProvider = (children: ReactNode) => {
  const { width, height } = useWindowSize();
  const isClient = useClient();
  const isMobile = isClient ? width < 1200 : false;

  return (
    <AppContext.Provider
      value={{
        isClient,
        isMobile,
      }}
    >
      {children}
    </AppContext.Provider>
  );
};

got this with export const AppProvider = (children: React.ReactNode) => {

Type error: Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & ReactNode'.
  Type '{ children: Element; }' is missing the following properties from type 'ReactPortal': key, type, props
like image 462
János Avatar asked Oct 21 '25 17:10

János


1 Answers

If it is defined as children prop the problem goes away.

interface IProps {
  children: React.ReactNode;
}
export const AppProvider = ({children}: IProps ) => {}
like image 154
Okan Karadag Avatar answered Oct 23 '25 08:10

Okan Karadag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!