I want to make simple CRUD functionality which should be the same in my web app, Android app and iOS app.
Therefore, I have in node.js
made an API from which I can retrieve a paginated list of all documents, a detail page of each document, and post/put requests to delete and update.
Now I am able to check for administrator rights and other things at these routes. Is this the correct approach?
Now I want to traverse this paginated list and present it with reactjs.
I guess it could be done with
import React from 'react';
import ReactDOM from 'react-dom';
export default class ItemLister extends React.Component {
constructor() {
super();
this.state = { items: [] };
console.log('test');
}
componentDidMount() {
fetch('/api/events/').then(result => {
this.setState({items:result.json()});
});
}
render() {
return (
<div>
<div>Items:</div>
{ this.state.items.map(item => { return <div>{http://item.name}</div>}) }
</div>
);
}
}
ReactDOM.render(<ItemLister/>, document.getElementById('hello-world'));
but nothing happens (it doesn't even print anything in the console window as i tried in the constructor).
I have this script in a file /components/ItemLister.jsx
and I have imported react-15.2.1
and react-dom-15.2.1
. I have installed babel-cli
, babel-preset-es2015
, babel-preset-react
and set
"presets": [
"es2015",
"react"
]
in my package.json
.