I have a custom hook with a useState holding a boolean value and function that allows me to update the state, I was expecting react to trigger a re render based on the new value but nothing happens
import React, { useState, useEffect } from 'react';
function useHook() {
const [value, setValue] = useState(false);
const onClick = (v) => {
setValue(v);
};
return {value, onClick};
}
const Switcher = () => {
const {value, onClick} = useHook();
return <button onClick={() => onClick(!value)}>test</button>;
};
export default function App() {
const {value} = useHook();
useEffect(() => {
console.log('effect', value);
}, [value]);
return (
<div>
<h1>Hello StackBlitz!</h1>
<p>result {JSON.stringify(value)}</p>
<Switcher />
</div>
);
}