-
-
Save wbobeirne/1c38f20bfe7664f8673ef99b83fd675c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const INITIAL_STATE: State = { | |
name: '', | |
content: '', | |
isPosting: false, | |
pendingPost: null, | |
paymentRequest: null, | |
error: null, | |
}; | |
export default class PostForm extends React.Component<Props, State> { | |
state = { ...INITIAL_STATE }; | |
componentDidUpdate() { | |
const { posts } = this.props; | |
const { pendingPost } = this.state; | |
// Reset the form if our pending post comes in | |
if (pendingPost) { | |
const hasPosted = !!posts.find(p => pendingPost.id === p.id); | |
if (hasPosted) { | |
this.setState({ ...INITIAL_STATE }); | |
} | |
} | |
} | |
/* ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment