DEV Community

Discussion on: Building Dynamic Breadcrumbs in NextJS

Collapse
 
florentinog9 profile image
FlorentinoG9

I fix it by doing this instead

inside the Crumb Component before the if( last) ....

    const router = useRouter()
    const [text, setText] = useState(defaultText)

    useEffect(() => {
        if ( !Boolean(textGenerator) ) return setText(defaultText)

        async function fetchData() {
            const currText = await textGenerator()
            setText(currText)
        }

        fetchData()

    }, [defaultText, textGenerator])
Enter fullscreen mode Exit fullscreen mode