Set state of the component with if a condition is met

I have decided to write this in a different post as it is about a different issue.

In the project that I am working now, I have created a collection “posts” where several users are allowed to write. I want each one of them to be able to edit or delete their own posts but not the other. In order to do that, I have stablished two states in the component that shows the data for each document and the state 0 has no icon to edit or delete, and the state 1 have them.

The dataSlot “ds_teacherID” has the data that has to match with the field “authorID” in the documents from the collection “posts” in Firestore. So what I did was to create the list/grid and in “Nested component” I selected to override state using the dataSlot “ds_teacherID” and write the script:

var teacherID = this.props.appActions.dataSlots[‘ds_teacherID’];
if (teacherID = this.state.authorID) {
return 1;
} else {
return 0;
}
return input;

However, I am not seing the state 1 even though I am the author and the data matches. Maybe I didn’t do the script well.

Thank you in advance!

Nevermind! I explored deeply the forum and I found the solution. I already tried it and it worked. The solution to this was here:

Thank you as always @Antti_Neonto and @Marcos_Alencar!

2 Likes