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
If you have two handler function, handlerOne and handlerTwo, and two components ComponentOne and ComponentTwo, you cannot call useFPReducer in ComponentOne with the handler-mapping object {RUN_HANDLER: handlerOne} and then call useFPReducer in ComponentTwo with the handler-mapping object {RUN_HANDLER: handlerTwo}. If the key RUN_HANDLER is re-used like this and ComponentOne is the first to render in your app, only handlerOne will be associated with the action {type: 'RUN_HANDLER'}. handlerTwo won't be registered with react-use-fp, and dispatching {type: 'RUN_HANDLER'} from ComponentTwo may cause handlerOne to run.
This is not a pit of success. React creates the expectation that the effects of any calls to dispatch will be limited to the state of the component that called useReducer; react-use-fp should honor that expectation. Manually ensuring uniqueness of every key of every handler-mapping object within the application is fragile. react-use-fp should implement some combination of the following behaviors:
Warn in dev mode whenever a user tries to register a handler to an action of a duplicate type
Panic/break in the above situation
Cause a typescript compiler error. Not sure this is possible.
Warn/break if a handler 'takes' an action that was dispatched from an inappropriate place
Maintain an association between a handler's initiating 'type' and the scope in which it was created, which would make it possible for duplicates to co-exist without problems, but would be tricky to implement without creating a memory leak whenever a component unmounted and re-mounted.
The text was updated successfully, but these errors were encountered:
Per the FAQ,
This is not a pit of success. React creates the expectation that the effects of any calls to dispatch will be limited to the state of the component that called
useReducer
;react-use-fp
should honor that expectation. Manually ensuring uniqueness of every key of every handler-mapping object within the application is fragile.react-use-fp
should implement some combination of the following behaviors:dev
mode whenever a user tries to register a handler to an action of a duplicate typeThe text was updated successfully, but these errors were encountered: