自定义hook
2020-08-18 本文已影响0人
一土二月鸟
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"));