I have problem with returning jsx code in React. I have a json object which looks like this:
{c0cdd544-2449-4f45-9ebf-e532a8f072c9: "no", 9c9f7415-7714-4d7f-96b8-9d627da5d210: "yes"}
I have function where I check if actual object.id exists in this json object. The problem is when I am trying to check it it works, it console.logs but it doesn't return my jsx code. Here is the statement:
if (object.id in json) {
console.log("has");
return <span>test</span>;
}
I tried ternary operator but it doesn't work too:
return json.hasOwnProperty(object.id) ? (
<span>test</span>
) : "";
Both console.logs "has" but the span doesn't show. The weird thing is that if I do it this way:
return true ? <span>test</span> : "";
It works and shows the span tag.
Any solutions? :)
Aucun commentaire:
Enregistrer un commentaire