How to use deps
codingedgar opened this issue · 3 comments
I'm sorry for the noob question, useEffect signature is:
useEffect ::
forall deps.
Eq deps =>
deps ->
Effect (Effect Unit) ->
Hook (UseEffect deps) Unit
useEffect deps effect =
unsafeHook do
runEffectFn3 useEffect_ (mkFn2 eq) deps effectin js I often use
useEffect (() => {
// ...
},
[stringDependency, booleanDependency]
)but useEffect has a homogenous deps, how can I have a deps list of different types?
I know this is more of a question about PureScript, but I think this is the best place to make this particular question and leave it for newcomers.
The deps in that signature isn't necessarily homogeneous, but polymorphic. So any deps can be passed as long as there is an Eq instance for that type. This is different from JS where you must provide dependencies in a tuple.
If you want a heterogeneous collection in PureScript, you could use a tuple or a record (which both have an Eq instance if the types they contain have Eq instances):
Hooks.useEffect { stringDependency, booleanDependency } do
-- ..or
Hooks.useEffect (stringDependency /\ booleanDependency) do
-- ..Thanks a lot! ✨
Perfect, thanks @ptrfrncsmrph 🙂
I'm actually working on docs right now! I swear!!