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 PureScript I don't think we have a giant sum type representing all the possible event types in this WindowEventMap (at least that I'm aware of) so you'd probably just want to have a smaller sum type of the events you want to handle
Activity
pete-murphy commentedon Feb 20, 2022
I don't have much experience using FFI for hooks, but I put together a small example to give one idea of how you could go about it here: https://github.com/ptrfrncsmrph/demo-foreign-import-hooks/blob/main/src/Foreign/Hooks.purs
Usage would look like: https://github.com/ptrfrncsmrph/demo-foreign-import-hooks/blob/eb7523b16957df1465d79c81bb87b3178a8ff0da/src/App.purs#L14-L35
In PureScript I don't think we have a giant sum type representing all the possible event types in this
WindowEventMap(at least that I'm aware of) so you'd probably just want to have a smaller sum type of the events you want to handleIn my example I've got the
mouseEventargument required inuseOnClickOutside, though it's optional in TS. You could use aMaybeor to get the same convenience of allowing caller to omit it, you could probably do something with https://github.com/joneshf/purescript-option#how-to-make-a-function-with-required-and-optional-values (though I haven't used that library).pete-murphy commentedon Feb 20, 2022
I'm not sure if it's good practice to leave the internal
hooksopaque in something likeinstead of typing them out like in https://github.com/megamaddu/purescript-react-basic-hooks/blob/4904b69821579f2c1fc3cac9f730892380216661/src/React/Basic/Hooks/Aff.purs#L58-L63
I'd imagine you'd want to leave them as just opaque
hooksbecause you don't own the implementation 🤷.dnikolovv commentedon Feb 21, 2022
Wow, thanks! Maybe this should make it into the docs or at least the cook books?