Hồng Phúc

35 bundles
1 filea month ago
1

const [likeProduct, setLikeProduct] = useState()

1234567891011121314151617181920212223242526272829303132
const [likeProduct, setLikeProduct] = useState(); const [id, setId] = useState(); const productId = useParams().productId; const getLike = () => { return axios.get(`http://localhost:5000/api/products/${productId}`); }; useEffect(() => { axios.get(`http://localhost:5000/api/products/${productId}`).then((res) => { const id = res.data; console.log(id); setId(id); }); }, []); const handleSumit = async () => { axios .post(`http://localhost:5000/api/products/${productId}`) .then(() => { getLike().then((res) => { setLikeProduct(res.data.likeProduct); }); }); }; useEffect(() => { getLike().then((res) => { setLikeProduct(res.data.likeProduct); }); }, []);