React + Typescript...Its return type 'Element | undefined' is not a valid JSX element.

React + Typescript...Its return type 'Element | undefined' is not a valid JSX element. I have a component where I did consume from an API that returns an array of objects but the parent component is giving me some error that says 'UsersTable' cannot be used as a JSX component. Its return type 'Element | undefined' is not a valid JSX element. Type 'undefined' is not assignable to type 'Element | null'. Please how do I get rid of this error?
13 Replies
Neto
Neto2y ago
you cant return a plain array in a component just jsx/tsx also the if(isSuccess) is probably the error because its reads if(isSuccess) return the data and looks like there is more on the file than the first print
Leke
Leke2y ago
I just removed the if(success) and the error is gone but i have another error
Neto
Neto2y ago
what error?
Leke
Leke2y ago
Neto
Neto2y ago
its correct if can do something with if(!data) ... to the tsserver be happy or data?.map usually the data?. is better too look at
Leke
Leke2y ago
its not working
Neto
Neto2y ago
after the if error if(!data) return null; and then the return with map
Leke
Leke2y ago
Leke
Leke2y ago
The error still persist
Neto
Neto2y ago
what is the error? on image it doesnt show
Leke
Leke2y ago
This is where the error is happening
Leke
Leke2y ago
The error says
Leke
Leke2y ago
I have resolved it Thank you
Want results from more Discord servers?
Add your server