Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import { Redirect } from 'react-router'
  3.  
  4. export default class ContactForm extends Component {
  5. constructor () {
  6. super();
  7. this.state = {
  8. fireRedirect: false
  9. }
  10. }
  11.  
  12. submitForm = (e) => {
  13. e.preventDefault()
  14. this.setState({ fireRedirect: true })
  15. }
  16.  
  17. render () {
  18. const { from } = this.props.location.state || '/'
  19. const { fireRedirect } = this.state
  20.  
  21. return (
  22. <div>
  23. <form onSubmit={this.submitForm}>
  24. <button type="submit">Submit</button>
  25. </form>
  26. {fireRedirect && (
  27. <Redirect to={from || '/thank-you'}/>
  28. )}
  29. </div>
  30. )
  31.  
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement