componentDidMount() {
try{
/*const decoded = jwt_decode(window.$userToken);
console.log(decoded);
this.setState({
username: decoded.username,
firstName: decoded.firstName,
lastName: decoded.lastName,
jerseyNumber: decoded.jerseyNumber
});*/
loadPlayerData().then(response => {
const data = response.data.data;
console.log(data);
const player = data.map(p =>
<div>
{
localStorage.username === p.username ? console.log("yes") : console.log("no")
}
<p className="m-0">
{localStorage.username === p.username ? "Name: " + p.firstName + " " : null}
{localStorage.username === p.username ? p.lastName : null}
</p>
<p className="m-0">
{localStorage.username === p.username ? "Jersey Number: " + p.jerseyNumber : null}
</p>
<p className="m-0">
{localStorage.username === p.username ? p.height <= 0 ? "No saved height" : "Height: " + p.height + "cm" : null}
</p>
<p className="m-0">
{localStorage.username === p.username ? p.weight <= 0 ? "No saved weight" : "Weight: " + p.weight + "kg" : null}
</p>
<p className="m-0">
{localStorage.username === p.username ? p.isAdmin === 1 ? "Admin: Yes" : "Admin: No" : null}
</p>
<p className="m-0">
{localStorage.username === p.username ? p.isFormer === 1 ? "Former Player: Yes" : "Former Player: No" : null}
</p>
{localStorage.username === p.username ? console.log(this.state.username = p.lastName) : null}
{localStorage.username === p.username ? console.log(this.state.username = p.lastName) : null}
</div>
);
this.setState({player})})
.catch(err => {
console.log(err);
throw err})
}catch (e) {
console.log(e);
}
}
This is what I have so far. I would like to be able to use the outputted data also on a different page and I have little to no idea how to do that. I am planning to make an "admin only page" where I can delete users.
Mockup of how I imagine the admin page to look like
As you can see in the mockup, I would like to output the username in there as well.
I am grateful for any help!!
componentDidMountevent? It seems that you're using axios for getting the data from the DB. When the promise is resolved just update the state of the component and in the render method run the map iterator to render all the elements. The initial state should be an empty array so when there is no data nothing gets rendered.render().componentDidMount()should save state that is later used inrender(). Also, I would suggest finding a way to avoid repeating the same boolean condition so often. One way to do that is with anifstatement and callingsetState(). Then you render directly from the values in state.