{this.props.sample.sample}
17 | 18 | {this.props.sample.show && 19 |{this.state.text}
29 | 30 | > 31 | ); 32 | } 33 | 34 | private handleClick = () => { 35 | Promise.resolve() 36 | .then(() => { 37 | this.props.sample.setShow(false); 38 | this.setState({ 39 | text: 'change', 40 | }); 41 | }); 42 | } 43 | } 44 | 45 | export default injectComponent{sample.sample}
33 |{secondary.test}
34 | > 35 | ); 36 | } 37 | 38 | beforeEach(() => { 39 | root = document.createElement('div'); 40 | document.body.appendChild(root); 41 | 42 | container = initContainer(true); 43 | 44 | context = createContext(container); 45 | }); 46 | 47 | afterEach(() => { 48 | document.body.removeChild(root); 49 | }); 50 | 51 | it('can render and react to updates', () => { 52 | const sampleService: SampleService = container.get(sampleIdent); 53 | const secondaryService = container.get(SecondaryService); 54 | 55 | // Test initial render. 56 | act(() => { 57 | ReactDOM.render({dataService.data}
64 | ); 65 | } 66 | 67 | export default injectComponent{data}
100 | ); 101 | } 102 | 103 | export default injectComponent{data}
167 | ); 168 | } 169 | ``` 170 | 171 | You can also use the `useInject` function provided in `createInjection`. Doing so would mean the App component would look like this: 172 | 173 | ```tsx 174 | function App() { 175 | const { dataService } = useInject(services); 176 | const data = dateService.data; 177 | 178 | return ( 179 |{data}
180 | ); 181 | } 182 | ``` 183 | -------------------------------------------------------------------------------- /src/create-injection.tsx: -------------------------------------------------------------------------------- 1 | import { Container, interfaces as inversifyTypes } from 'inversify'; 2 | import React, { Component, ComponentType, createContext, ReactNode } from 'react'; 3 | import { StateTracker } from './state-tracker'; 4 | import { useInjection } from './use-injection'; 5 | 6 | // ------ react-redux type definitions ------ 7 | 8 | type Omit{this.props.normalProp}
49 |{this.props.sampleService.sample}
50 | > 51 | ); 52 | } 53 | } 54 | 55 | class SecondaryComponent extends Component{this.props.secondaryService.test}
; 63 | } 64 | } 65 | 66 | class StateMappedComponent extends Component<{ testValue: string }> { 67 | public constructor(props: { testValue: string }) { 68 | super(props); 69 | } 70 | 71 | public render() { 72 | return{this.props.testValue}
; 73 | } 74 | } 75 | 76 | function init() { 77 | return { 78 | div: document.createElement('div'), 79 | IP: injection.InjectionProvider, 80 | InjectedComponent: injection.injectComponenttest
; 238 | }); 239 | 240 | const cnt = new Container(); 241 | cnt.bind(TestService).toSelf(); 242 | 243 | ReactDOM.render( 244 |