Why do government libraries use react context for dependency injection?
I looked at the source code of two well-known government control systems for React and found out that both of them use the React context as a dependency container ( MobxProvider
, ReduxProvider
). On the other hand, I find it good practice to try not to use React related constructors for libraries (especially context), and I think it is possible to create a separate module for the dependency container. Here is a naive implementation of my thoughts:
let container = {};
const register = (obj) => {
Object.assign(container, obj);
}
const getAll = () => container;
export { getAll, register };
Am I missing something? Are there any edge cases that cannot be maintained just by using a module? Why are they using context as their dependency container in React?
source to share
No one has answered this question yet
Check out similar questions: