I'm making simple To-Do App in ReactJS.For now I'm adding Routes I managed to implement .post
method,but now I'm stuck on .get
Method,it's being looped and is rendering over and over again.
Here is what am I doing.
state = {
inputValue: '',
todos: [],
currentPage: 1,
pageCount: 1,
itemsPerPage: 10,
};
getAll = () => {
let {todos} = this.state
axios
.get("http://localhost:8080/", {
todos:todos
})
.then((res) => {
this.setState({todos:res.data})
})
.catch((err) => {
console.log("err", err);
});
};
render() {
const {itemsPerPage, currentPage, todos} = this.state;
const end = currentPage * itemsPerPage
const start = end - itemsPerPage
const currentItems = todos.slice(start, end);
return <div className={"App"}>
<div className="App-header">
<h2>Welcome to To-Do List App</h2>
</div>
<input ref={this.inpRef} onKeyPress={this.handleKeyPress} name={''} type='text'/>
<button onClick={() => this.addItem()} className={'btn btn-primary'}>Add</button>
<ul>
{
todos.length ?
currentItems.map(todoItem => <ListItem
key={todoItem.id}
todoItem={todoItem}
deleteItem={this.deleteItem}
editItem={this.editItem}
submitEdit={this.submitEdit}
getAll = {this.getAll}
/>) :
null
}
<div>
{this.getAll()}
{this.renderPagination()}
</div>
</ul>
</div>
};
}
export default App;
All I want to do is to Render received data into <ul>
and make it appear as li
,But the problem is it is stuck in infinite loop and is updating page over and over again.
Any suggestions?