我有这个自定义钩子
const useShowBg = () => {
const [showBg, useShowBg] = useState(false);
return [showBg, useShowBg];
};
export default useShowBg;
我将其导入组件并像这样使用
import myHook from './myHook';
const App = () => {
const [showBg, useShowBg] = myHook
return (
<div>
<button onClick={() => useShowBg(true)}>show</button>
{showBg && <p>
Start editing to see some magic happen :)
</p>}
</div>
);
}
单击以触发函数时出现useShowBg is not a function
错误?有什么问题吗?
答案 0 :(得分:0)
您忘记了调用钩子
const [showBg, useShowBg] = myHook()