Skip to content

Commit

Permalink
Added logic to wire-up the 'Add new item...' button to prompt the use…
Browse files Browse the repository at this point in the history
…r for the new item when clicked, and to update the <ListWidget> 'state' field 'items' to a new array of items including the just-added item, to cause it to be re-rendered by React with that new item.
  • Loading branch information
maratbn committed Aug 5, 2018
1 parent 83e7ace commit 74cf9b3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion webpack_in/entry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,23 @@ class ListWidget extends React.Component {
</ul>
</div>
<div>
<ButtonWidget caption="Add new item..." />
<ButtonWidget caption="Add new item..."
onClick={() => {
const strItemNew = prompt("Please enter new item to add:",
"Item "
+ (this.state.items.length + 1));
if (strItemNew === null) {
return;
}

this.setState({
...this.state,
items: [
...this.state.items,
strItemNew
]
});
}}/>
<ButtonWidget caption="Edit item..." />
<ButtonWidget caption="Remove item..." />
</div>
Expand Down

0 comments on commit 74cf9b3

Please sign in to comment.