Hello guys, I have a problem rendering a component in react
{ url && <Youtube url={url} }
the component displays fine when I have an URL prop, but when I don't have a URL, it renders a blank screen and I can't see any information in the console or "react developer tool"
anybody know the reason !?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (3)
Do you have an actual code snippet you can post? You seem to be missing the closing bracket for your Youtube component, but that might just be a typo.
The blank screen is probably correct since your code is essentially saying that if
url
exists, keep going and render<Youtube url={url} />
. Ifurl
doesn't exist, it stops evaluating that expression.Add logic inside Youtube component. If props is null or not an url return error or else
Instead of && try use ternary operator. Url? :
no url
.
Check if your URL is string or not. I mean try logging in Or something