Recently when I was coding in react and when I tried to run my app I got an unexpected error; Property ‘children’ does not exist on type ‘IPageProps’. A snippet of the error is given below. A snippet of the error I got is given below.
Property 'children' does not exist on type 'IPageProps'
I would like to share the steps that helped me to fix the error; Property ‘children’ does not exist on type ‘IPageProps’
Why Property ‘children’ does not exist on type ‘IPageProps’ error is seen?
The error, “Property ‘children’ does not exist on type ‘IPageProps,'” is seen because of the new update of React version 18. In the previous versions of React children props were included in the FC
interface but, the children
prop was removed from the FunctionComponent (React.FC
) in the latest update of React 18, so now you have to add it manually.
A detailed solution to fix the Property ‘children’ does not exist on type ‘IPageProps’ error is provided below:
How to fix Property ‘children’ does not exist on type ‘IPageProps’ error?
A simple solution to fix this would be to define the children prop manually. In the new version of React 18, the children
is a regular prop and is not a special class. So you need to call or define it just like you define any other props in React 18. An alternative solution would be to stop using React.FC all together.
To resolve the error Property ‘children’ does not exist on type ‘IPageProps’ you must follow the below steps:
Since the children
prop was removed from the FunctionComponent (React.FC) in the latest update of React 18, so now you have to add it manually.
To add the children prop on React 18 just follow the below-mentioned code.
import * as React from 'react';
type Props = {
children?: React.ReactNode
};
const Component: React.FC<Props> = ({children}) => {...}
An alternative solution would be to stop using React.FC all together. Follow the code below-mentioned to stop using React.FC to avoid the error, Property ‘children’ does not exist on type ‘IPageProps’ error
import * as React from 'react';
type Props = {
children?: React.ReactNode
};
function Component({children}: Props): React.ReactNode {
...
This should fix the problem.
Conclusion
To fix the Property ‘children’ does not exist on type ‘IPageProps’ error; you would have to define the children prop manually. In the new version of React 18, the children
is a regular prop and is not a special class. So you need to call or define it just like you define any other props in React 18. An alternative solution would be to stop using React.FC all together.