Skip to content

Instantly share code, notes, and snippets.

@wbobeirne
Created May 21, 2019 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbobeirne/1c38f20bfe7664f8673ef99b83fd675c to your computer and use it in GitHub Desktop.
Save wbobeirne/1c38f20bfe7664f8673ef99b83fd675c to your computer and use it in GitHub Desktop.
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