Hooks.purs 534 Bytes
Newer Older
James Laver's avatar
James Laver committed
1 2
module Gargantext.Hooks ( useHashRouter ) where

3
import Prelude (Unit, ($))
James Laver's avatar
James Laver committed
4 5 6 7 8 9 10 11 12 13
import Reactix as R
import Routing.Match (Match)
import Routing.Hash (matches)
import Toestand as T

-- | Sets up the hash router so it writes the route to the given cell.
-- | Note: if it gets sent to an unrecognised url, it will quietly
-- | drop the change.
useHashRouter :: forall r c. T.Write c r => Match r -> c -> R.Hooks Unit
useHashRouter routes cell = R.useEffectOnce $ matches routes h where
14
  h _old new = T.write_ new cell
James Laver's avatar
James Laver committed
15 16

-- useSession cell =