Skip to content
Snippets Groups Projects
Upvote.js 849 B
Newer Older
  • Learn to ignore specific revisions
  • ludvighillert's avatar
    ludvighillert committed
    import React, { useState } from 'react';
    import axios from 'axios'
    
    ludvighillert's avatar
    ludvighillert committed
    import styles from '../styles/feed.module.css'
    
    const Upvote = ({postId}) =>{
    
    ludvighillert's avatar
    ludvighillert committed
        const [count, setCount] = useState(0);
    
        const [upvotes, setUpvotes] = useState(0);
    
    ludvighillert's avatar
    ludvighillert committed
    
    
        const increment = () => {
            setCount(count + 1)
        }
    
        const decrement = () => {
            setCount(count - 1)
        }
    
        if (count<0){
            setCount(0);
        }
    
    
    ludvighillert's avatar
    ludvighillert committed
       // const formData = new FormData()
      
            //formData.append('Upvotes',count);
    
            //axios.post("http://localhost:5000/save", 
           // formData
           // )
        return (
            <div className = {styles.upvote}>
                <button className={styles.upvote} onClick={increment}>
    
    ludvighillert's avatar
    ludvighillert committed
                    🍺
    
    ludvighillert's avatar
    ludvighillert committed
                </button>
                 <div>{count}</div>
    
    ludvighillert's avatar
    ludvighillert committed
               
            </div>
        )
    }
    
    export default Upvote;