I need to implement a clear/reset for the inputs after onClick occurs, and also after it is stored in localStorage. I can't seem to figure out how to code this and where. Here is my add function and render function.
addExpense(e) {
e.preventDefault()
let exList = this.state.exList
if (this.state.expense === null) {
alert('Please enter a name.')
return false
}
if (this.state.amount === 0) {
alert('Please enter a valid amount.')
return false
}
if(isNaN(this.state.amount)) {
alert('The amount must be a number.')
return false
}
this.state.exList.push({ 'title':this.state.title, 'amount':this.state.amount })
this.setState({ exList: this.state.exList })
localStorage.setItem('exList', JSON.stringify(exList))
}
render() {
let myExpenses = this.state.exList.map((val, key) => { return <ExpenseList val={val} key={key} id={key} delMe={() =>this.removeExpense(key) } />
})
return (
<main className="ContactList">
<section className="add container">
<h2 className="newExpense">Add Expense</h2>
<form name="myForm">
<p>
<label>Title </label>
<input type="text" name="title" onChange= .
{this.changeExpense} />
<label>Amount </label>
<input type="text" name="amount" onChange= .
{this.changeAmount} />
<button type="submit" className="btn" onClick= .
{this.addExpense}>Add</button>
</p>
</form>
</section>
<section className="container">
<h3 className="currentExpense">Current Expenses</h3>
<article className="contentScroll">
<ul className="expenseCont">{myExpenses}</ul>
</article>
</section>
</main>
)
}