Im trying to activate a function with reactjs
But i keep getting the same error:
Uncaught TypeError: Class constructor Upload cannot be invoked without ‘new’
i dont know what to do with it:
import React, { Component } from 'react';
export class Upload extends Component {
static displayName = Upload.name;
constructor(props) {
super(props);
this.state = {
Title: "empty",
Price: 1,
Description: "empty description",
quantity: 2,
loading: true
};
}
Upload = () =>{
const item =
{
title: this.state.Title,
price: this.state.Price,
description: this.state.Description,
quantity: this.state.quantity
};
fetch('api/Upload', {
method: 'POST',
body: JSON.stringify(item)
}).then(response => response.json())
.then(data => console.log('succes', data))
.catch(error => console.error("unable to achive this", error))
}
render() {
return (
<div>
<h1>Upload here</h1>
<button id="uploadbutton" onClick={ Upload }>Upload the product</button>
</div>
);
}
}