-1

I kindly I need help rectifying this typeScript error:

Type '() => boolean' is not assignable to type 'ReactNode'.ts(2322)

Below is a sample of my code:

export const Palindrome:React.FC<{}> = () => {

    const results = ():boolean => {

        const int = 121;
        return String(int) === String(int).split('').reverse().join();
    };

    return (
        <div>
            {results}
        </div>
    )

}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Temisan Momodu
  • 99
  • 1
  • 1
  • 6
  • It doesn't know how to render your `function` as a JSX element. What are you trying to render inside that `div`? – choz Jun 29 '22 at 07:36
  • Please do not edit your question to remove the original problem. I have rolled back your edit. Instead, accept one of the answers that pointed out the problem. – Mark Rotteveel Jul 02 '22 at 09:42

2 Answers2

2

You forgot to call the function, you are passing its reference instead, which React doesn't know what to do with.

export const Palindrome:React.FC<{}> = () => {
    const results = ():boolean => {
        const int = 121;
        return String(int) === String(int).split('').reverse().join();
    };

    return (
        <div>
            {results()} {/* add () like here */}
        </div>
    )
}
casraf
  • 21,085
  • 9
  • 56
  • 91
1

You're not calling the results function. Change to this

return (
    <div>
        {results()}
    </div>
)