I am new to the React world and am struggling to get my JSON data to display in a table.
class GetUnassignedUsers extends React.Component {
constructor () {
super();
this.state = {
data:[]
};
}
componentDidMount () {
fetch("http://localhost/dashboard/?action=unassignedUsers.getUnassingedUsers", {
credentials: 'same-origin'
})
.then(response => response.json())
.then(json => this.setState({data: json}));
}
render () {
console.log("teams", this.state.data.teams);
console.log("unassignedUsers", this.state.data.unassignedUsers);
var teams = this.state.data.teams;
var unassignedUsers = this.state.data.unassignedUsers;
return (
<tr>
<td>
{unassignedUsers.ID}
</td>
<td>
23/08/2015
</td>
<td>
Tradeprint
</td>
<td>
[email protected]
</td>
<td>
John Bloggs
</td>
<td>
Aberfeldy
</td>
<td>
AD9 8QR
</td>
<td>
Unassigned
</td>
</tr>
);
}
};
export default GetUnassignedClients;
I am accessing the JSON and returning it in the render method in the 2 console logs (console.log("teams", this.state.data.teams); and console.log("unassignedUsers", this.state.data.unassignedUsers);).
My issue is below that where I tidy up the dot notation by declaring the 2 variables for teams and unassignedUsers. Then in my return I want to produce a row for each JSON record with the unassignedUser ID in the first <td>.