React – Warning: Functions are not valid as a React child

React

React lets you build user interfaces out of individual pieces called components. Create your own React components like Thumbnail, LikeButton, and Video. Then combine them into entire screens, pages, and apps.

How to reproduce it

export default function WarningDemo() {

    const fun = () => 0;

    return (
        <>
            {fun}
        </>
    );
}

Warning

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
    at WarningDemo
    at div
    at App

Solution

You have to call the function.


export default function WarningDemo() {

    const fun = () => 0;

    return (
        <>
            {fun()}
        </>
    );
}
https://www.mldgroup.com

Vyštudovaný top manažér pôsobiaci najmä ako manažér, marketér, softvérový inžinier, konzultant, bloger, YouTuber a zatiaľ neúspešný hudobník a producent. V rámci praxe pôsobil v rôznych odvetviach na rôznych pozíciách v malých aj veľkých firmách, vrátane spoluprác a partnerstiev s významnými firmami či poradenskými spoločnosťami.

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *