import { createWideHook } from 'widehook'
export const useMessage = createWideHook({
init: 'text',
})
const Button = () => {
const [message, setMessage] = useMessage()
const click = () => setMessage('One Value')
return <button onClick={click}>
{message}
</button>
}
const setSpecialMessage = (text: string) => {
const [message, setMessage] = useMessage()
setMessage(text)
}
If set - hook returns an object with named props and methods:
const useCounter = createWideHook({
init: 3,
objectifyWithName: 'counter',
})
...
const { counter, setCounter } = useCounter()
On each "setState"
define action:
export const useMessage = createWideHook({
init: 'text',
on(text, setText) {
if (text === 'specific message') setText('another text')
},
})
Take another widehook to read and update:
export const useText = createWideHook({
init: 'text',
on(text, setText) {
const [number, setNumber] = useNumber()
if (text === 'specific text') setNumber(7)
},
})