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
dispatchreturned fromuseFPReducer?
A: Not completely, yet. The compiler will warn you if you try to dispatch an action with atypethat’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,useFPReducerwill 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,handlerOneandhandlerTwo, and two componentsComponentOneandComponentTwo, you cannot calluseFPReducerinComponentOnewith the handler-mapping object{RUN_HANDLER: handlerOne}and then calluseFPReducerinComponentTwowith the handler-mapping object{RUN_HANDLER: handlerTwo}. If the keyRUN_HANDLERis re-used like this andComponentOneis the first to render in your app, onlyhandlerOnewill be associated with the action{type: 'RUN_HANDLER'}.handlerTwowon’t be registered withreact-use-fp, and dispatching{type: 'RUN_HANDLER'}fromComponentTwomay causehandlerOneto 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.