Skip to content

Commit

Permalink
fix deletion in questions-with-form
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin Witherspoon committed Aug 24, 2018
1 parent 299da19 commit c4bf205
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/question-form.js
Expand Up @@ -58,7 +58,7 @@ export default class QuestionForm extends React.Component {
value: { id },
onCancel
} = this.props;
if (id) {
if (!isNil(id)) {
return (
<React.Fragment>
<Button variant="raised" color="default" onClick={onCancel}>
Expand Down
30 changes: 15 additions & 15 deletions examples/questions-with-form.js
Expand Up @@ -11,8 +11,18 @@ export default class QuestionsWithForm extends React.Component {

state = {
nextId: 2,
questions: [
{
questions: {
0: {
author: {
firstName: "Bob",
lastName: "B"
},
body: "I installed package x and now my code doesn't work.",
id: 0,
tags: ["javascript"],
title: "I have a bug"
},
1: {
author: {
firstName: "Alice",
lastName: "A"
Expand All @@ -22,18 +32,8 @@ export default class QuestionsWithForm extends React.Component {
id: 1,
tags: ["react", "redux"],
title: "How do I connect a component to react redux"
},
{
author: {
firstName: "Bob",
lastName: "B"
},
body: "I installed package x and now my code doesn't work.",
id: 0,
tags: ["javascript"],
title: "I have a bug"
}
]
}
};

handleCommit = (message, value) => {
Expand All @@ -56,7 +56,7 @@ export default class QuestionsWithForm extends React.Component {
}));
case "DELETE":
return this.setState(prevState => ({
questions: omit(prevState.questions, value.id)
questions: omit([value.id], prevState.questions)
}));
default:
throw new Error("bad message");
Expand All @@ -68,7 +68,7 @@ export default class QuestionsWithForm extends React.Component {
sortBy(prop("id")),
reverse,
map(question => (
<Editable value={question} onCommit={this.handleCommit}>
<Editable key={question.id} value={question} onCommit={this.handleCommit}>
{editableProps => <QuestionForm {...editableProps} />}
</Editable>
))
Expand Down

0 comments on commit c4bf205

Please sign in to comment.