usage
import React, { useEffect, useState } from "react";
import ReactDom from "react-dom";
const useProduct = (productName) => {
const [proList, setProList] = useState([]);
useEffect(() => {
setTimeout(() => {
setProList([1, 2, 3]);
}, 1000);
}, []);
return proList;
}
const Index = () => {
const proList = useProduct();
return <>
{proList.length}
</>;
}
ReactDom.render(<Index />, document.getElementById("root"));
网友评论