React instance injection ?
See original GitHub issuePure component factories let you inject your React instance into the component so that you can share a single React instance across your entire app – even if you load React from CDN for client use
I can’t see the advantage over using ES6 import React from 'react'
on each file - besides the repeated 1-line advantage, obviously. That, and the classic-er ES5 require
call provided by libs, gives you one same React instance on all components too. Am I missing something ?
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Dependency injection in React - LogRocket Blog
Dependency injection (DI) is a pattern where components necessary for your code to run are hot-swappable. This means that your dependencies ...
Read more >React Has Built-In Dependency Injection - Marmelab
Dependency Injection solves a common problem, which is hardcoded dependencies. When an object A depends on a second object B and creates that ......
Read more >Advanced Dependency Injection in React - Bits and Pieces
Dependency injection is a pattern that reduces hardcoded dependencies. It promotes composability by enabling one dependency to be replaced ...
Read more >Dependency Injection in React - Medium
React effectively has dependency injection built-in. Dependencies are essentially injected via properties. It's possible to inject scalar ...
Read more >Dependency Injection in React - 8th Light
Dependency Injection in React ... Dependency injection is a form of inversion of control. This means that a component's dependencies are not part ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep. You’re missing the fact that lots of apps load React from CDN for front-end code, as well as the fact that front end code may have more than one entry point (and may in fact be two completely different codebases) – if both entry points use React, you’ll get conflicts. Exporting a factory is the safest way to mitigate the situation.
For more on this problem and how common it is, see Two React Tips by Dan Abramov.
Open to a PR.