I have this custom hook
const useShowBg = () => {
const [showBg, useShowBg] = useState(false);
return [showBg, useShowBg];
};
export default useShowBg;
I import it in a component and use it like so
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>
);
}
I got useShowBg is not a function
error when I click to fire the function? something is wrong?
you forgot to invoke your hook
const [showBg, useShowBg] = myHook()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.