FAQ
-
Q: Do I really need fp-ts in my React project?
A: Like React Redux, Redux-Saga, Immer, etc., if you’re not sure if you need them, you probably don’t. But, when you do need it, it’s awfully nice to already know it! Particularly if your application needs to manipulate data in complicated ways, functional approaches have a lot to offer. -
Q: This seems a lot like Redux. Can I use this with Redux?
A: Not yet, but stay tuned! -
Q: How typesafe is the
dispatch
returned fromuseFPReducer
?
A: Not completely, yet. The compiler will warn you if you try to dispatch an action with atype
that’s not in your reducer (assuming you’ve typed the reducer correctly), but it will not warn you if you try to give it a payload of the wrong type. As of v.2.1.0,useFPReducer
will automatically generate action-creator functions for you Redux Toolkit-style, and they should be 100% typesafe. -
Q: Can I re-use the names of my action creators in a different component?
A: No. If you have two handler function,handlerOne
andhandlerTwo
, and two componentsComponentOne
andComponentTwo
, you cannot calluseFPReducer
inComponentOne
with the handler-mapping object{RUN_HANDLER: handlerOne}
and then calluseFPReducer
inComponentTwo
with the handler-mapping object{RUN_HANDLER: handlerTwo}
. If the keyRUN_HANDLER
is re-used like this andComponentOne
is the first to render in your app, onlyhandlerOne
will be associated with the action{type: 'RUN_HANDLER'}
.handlerTwo
won’t be registered withreact-use-fp
, and dispatching{type: 'RUN_HANDLER'}
fromComponentTwo
may causehandlerOne
to run. So for now, please use unique keys for your handler-mapping objects, and have a look at this issue if you have ideas to improve this. -
Q: None of this makes any sense, what should I do?
A: I’m sure the fault is mine, please feel free to open an issue! Suggestions/PRs/comments also welcome.