Reputation: 27
I have a problem understanding why this code isnt working. If i use it like this:
const [theInfo , setTheInfo] = useState(null);
return (
theInfo ?(
...):(
...)
Its working without any problems. But as soon as i add a View or anything above or after theInfo...
like this:
const [theInfo , setTheInfo] = useState(null);
return (
<View>
<View>
<Text>Hi</Text>
</View>
theInfo ?(
...):(
...)
</View>
Then I get this error: TypeError: null is not an object (evaluating 'theInfo.map')
I dont understand why this is happening. I want to set a searchbar on top, and after this the theInfo?(...
part
Upvotes: 0
Views: 254
Reputation: 439
theInfo is a variable, you can't use it jsx in such a way, inclose it in curly braces :
const [theInfo , setTheInfo] = useState(null);
return (
<View>
<View>
<Text>Hi</Text>
</View>
{
theInfo ?(
...):(
...)
}
</View>
Upvotes: 1