Skip to content

Commit 74cf9b3

Browse files
committed
Added logic to wire-up the 'Add new item...' button to prompt the user 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.
1 parent 83e7ace commit 74cf9b3

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎webpack_in/entry.jsx‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,23 @@ class ListWidget extends React.Component {
9898
</ul>
9999
</div>
100100
<div>
101-
<ButtonWidget caption="Add new item..." />
101+
<ButtonWidget caption="Add new item..."
102+
onClick={() => {
103+
const strItemNew = prompt("Please enter new item to add:",
104+
"Item "
105+
+ (this.state.items.length + 1));
106+
if (strItemNew === null) {
107+
return;
108+
}
109+
110+
this.setState({
111+
...this.state,
112+
items: [
113+
...this.state.items,
114+
strItemNew
115+
]
116+
});
117+
}}/>
102118
<ButtonWidget caption="Edit item..." />
103119
<ButtonWidget caption="Remove item..." />
104120
</div>

0 commit comments

Comments
 (0)