question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React instance injection ?

See original GitHub issue

Pure 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:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ericelliottcommented, Nov 3, 2015

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.

0reactions
ericelliottcommented, Jan 2, 2016

Open to a PR.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found