React form with <Popup> alert message instead of alert()
13:35 21 Oct 2018

I am trying to create a contact form in React. It sends the email. Everything is working fine. What I would like to achieve is to replace the alert('') with a better looking < Popup> message using react Popup package. Here is the code:

import React, { Component } from 'react';
import '../css/Contact.css';
import axios from 'axios';
import Popup from "reactjs-popup";

class Contact extends Component {

    constructor(props) {
        super(props);
        this.state = {
            name: '',
            email: '',
            message: '',
            isValid: false
        };
        this.handleChange = this.handleChange.bind(this);
        this.handleSubmit = this.handleSubmit.bind(this);
        this.validationCheck = this.validationCheck.bind(this);
    }

    handleChange = (event) => {
        const name = event.target.id;
        const value = event.target.value;
        this.setState ({ [name] : value});

    }

    validationCheck () {

        if((this.state.name.length)>3 &&
           (this.state.message.length)>5 &&
           (this.state.email.length)>7 &&
           (this.state.email.includes("@")) &&
           (this.state.email.includes(".")) &&
           ((this.state.name || this.state.message || this.state.message)!=0)
           )
        {
            this.setState({ isValid: true});
            this.forceUpdate();
        };

    }

    async handleSubmit (event) {
        this.validationCheck();
        this.forceUpdate();
        if ((this.state.isValid) === true) {
            event.preventDefault();         
            const { name, email, message } = this.state;
            const form = await axios.post('/api/form', {
            name,
            email,
            message
           });
                alert('thank you for your message');
                event.target.reset();


        }
        else {
            event.preventDefault();
            alert('you might have entered something wrong');
        }


        }


    render() {    
        return (
        

Contact Me


); } } export default Contact;

I have tried to replace 'alert('thank you for your message');' with return(< Popup>); but that is clearly not a way forward.

reactjs forms popup contacts