Problem Statement React element not loading on conditional rendering
What I have done till now
I have a simple condition and I want to render components based on that. Here's how it looks like. I want to render IoMdAdd when true
true
? (()=>(<Link><IoMdAdd size="25"/></Link>))
: (()=>(<Link><IoIosHeartEmpty size="25"/></Link>))
conversely, I want to show IoIosHeartEmpty when the condition is false
false
? (()=>(<Link><IoMdAdd size="25"/></Link>))
: (()=>(<Link><IoIosHeartEmpty size="25"/></Link>))
Current behavior It doesn't show anything. The element doesn't appear in the dom when I do inspect element.
Expected behavior Show one of the components based on the condition
Edit Since y'all are asking for more code, let me paste the entire component
import React, { Component } from "react";
import { Link } from "@reach/router";
import { IoIosHeartEmpty, IoMdAdd } from "react-icons/io";
import { connect } from "react-redux"
class Header extends Component {
render() {
return (
<div className="wishlist-icon">
{(localStorage.getItem("accessLevel") == "Admin" && this.state.loggedInUser.accessLevel == "Admin") ? (<Link to="AdminPage"><IoMdAdd size="25" /></Link>) : (<Link to="UserPage"><IoIosHeartEmpty size="25" /></Link>)}
</div>
);
}
}
const mapStateToProps = state => {
return {
loggedInUser: state.loggedInUser
}
}
export default connect(mapStateToProps)(Header)
If the user is admin, I want to show him an icon that links him to the admin page, otherwise, I want to take him to the user page.
stringstarts withsearch5 | var startsWith = function startsWith(string, search) { > 6 | return string.substr(0, search.length) === search; 7 | }; 8 | 9 | //////////////////////////////////////////////////////////////////////////////// ```