Skip to content Skip to sidebar Skip to footer

Reactjs Conditional Rendering: Component Being Rendered Even Though Rendering Conditions Are Not Met

CONTEXT: I only have this problem when I route directly to a modal route (putting the link in the url bar and pressing enter). this.props.photoId is actually a this.props.routePara

Solution 1:

Use this to have type check as well:

typeofthis.props.photoId !== 'undefined'

Solution 2:

The best way to conditionally render a component in React: https://reactjs.org/docs/conditional-rendering.html

Update your code to:

render() {
  returnthis.props.photoId ? <PhotoModal /> : null
}

This will also handle checking null, false and 0.

Post a Comment for "Reactjs Conditional Rendering: Component Being Rendered Even Though Rendering Conditions Are Not Met"