Comments (2)
Thanks! About your question, the answer is not quite. Each component needs to have di
called with the dependencies youโd like to replace, as that signals where you want the substitution to happen.
So you cannot just di
once, in the top component, as it will not know which setState to replace. The correct code is:
const ChildComponent = () => {
di(useState);
const [title, _setTitle] = useState("Hi there");
return <h2>{title}</h2>;
};
Basically the di
call needs to be in all your โrealโ components code for the system to work. That is why we developed a babel plugin to strip that code on production builds (so it does not affect performance) and also Eslint rules to help automate adding di
calls for all dependencies
from react-magnetic-di.
Sorry for the massively delayed response. You're a champion, thank you for responding to this so quickly!
from react-magnetic-di.
Related Issues (20)
- Mocking not functional with Jest + storybook + storyshots HOT 2
- Make node 10.16 the minimum supported version
- Issues with CRA and TypeScript HOT 3
- Add option to strip code on production build HOT 1
- Eslint errors on files without di
- eslint rule "react-magnetic-di/no-extraneous" unnecessarily injects Components provided via HOC
- Is it possible to update an injectable, i.e. make it dynamic? HOT 2
- Bug with exhaustive deps lint rule
- DiProvider prop-types does not support forwardRef replacement
- Error: "Invalid hook call. Hooks can only be called inside of the body of a function component." HOT 1
- unable to `di` in production mode HOT 3
- Babel plugin cannot be found HOT 5
- Add support for `react-test-renderer` HOT 3
- missing React hooks exemption for exhaustive-inject HOT 3
- Unbound Magnetic from React HOT 3
- Track used and unused mocks HOT 2
- Enzyme `wrappingComponent` doesn't work HOT 2
- DiProvider with global does not clean replacementMap on error HOT 3
- Is storybook 7 supported? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-magnetic-di.