Skip to content
Advertisement

FlatList conditional rendering if {user === owner || gues}

In my Applikation I render a Expo FlatList to show created Events.

List Preview

If the user has created or joined this event, he should be able to see the images. If not, they should be hidden.

I would now store the creator and the guests in the database and would have to compare this with the currentUser from the Firebase Auth beforehand.

However, I face the problem that I can’t tell the FlatList which items should be rendered and which shouldn’t.

Does anyone knows a solution for conditional render a FlatList?

Fullcode

JavaScript

Advertisement

Answer

You can filter the events data before setting it to the state

I am assuming, events have a owner property which is the userId, it has an array of userIds in guests property

JavaScript
Advertisement