You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following example based on the counter example:
moduleReactExamplewhereimportPreludeimportData.Maybe (Maybe(..))
importEffect (Effect)
importEffect.ConsoleasConsoleimportEffect.Exception (throw)
importReact.Basic.DOM (render)
importReact.Basic.DOMasRimportReact.Basic.Events (handler_)
importReact.Basic.Hooks (Component, component, fragment, useEffect, useEffectAlways, useState, (/\))
importReact.Basic.HooksasReactimportWeb.DOM.NonElementParentNode (getElementById)
importWeb.HTML (window)
importWeb.HTML.HTMLDocument (toNonElementParentNode)
importWeb.HTML.Window (document)
mkExample::ComponentUnit
mkExample = do
component "Counter" \_ ->React.do
counter /\ setCounter <- useState 0
useEffect counter $ Console.log ("useEffect " <> show counter) *> pure mempty
useEffectAlways $ Console.log ("useEffectAlways " <> show counter) *> pure mempty
pure
$ fragment
[ R.button
{ onClick: handler_ $ setCounter (_ + 1)
, children: [ R.text $ "Increment: " <> show counter ]
}
]
main::EffectUnit
main = do
container <- getElementById "container" =<< (map toNonElementParentNode $ document =<< window)
case container ofNothing-> throw "Container element not found."Just c ->do
ex <- mkExample
render (ex unit) c
Hitting the increment button runs the useEffect hook but does not run the useEffectAlways hook. I expected the -Always hook to run at least as often as any sibling effect hook, but it appears this is not the case. Could you help me understand why?
Thanks for an awesome library 🙏 !
The text was updated successfully, but these errors were encountered:
In the following example based on the counter example:
Hitting the increment button runs the
useEffect
hook but does not run theuseEffectAlways
hook. I expected the -Always hook to run at least as often as any sibling effect hook, but it appears this is not the case. Could you help me understand why?Thanks for an awesome library 🙏 !
The text was updated successfully, but these errors were encountered: