docs: Embedding in existing react App (#1626)

Added how to embed OHIF viewer in an existing React application
This commit is contained in:
Nisal Upendra 2020-04-10 14:28:37 +02:00 committed by GitHub
parent d769e5c296
commit 2412c08595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,12 +126,39 @@ globally defined styles/scripts.
> We're trying to embed the OHIF Viewer into an existing React App, but seeing > We're trying to embed the OHIF Viewer into an existing React App, but seeing
> react-dom and react conflicts. What can we do? > react-dom and react conflicts. What can we do?
If you are installing OHIF viewer inside another react app, you may use `installViewer` as follows:
```
import { installViewer } from '@ohif/viewer'
const ohifViewerConfig = window.config // or set it here
const containerId = 'ohif'
const componentRenderedOrUpdatedCallback = function() {
console.log('OHIF Viewer rendered/updated');
};
componentDidMount() {
installViewer(
ohifViewerConfig,
containerId,
componentRenderedOrUpdatedCallback
);
}
render () {
...
//you can render in any element you wish
<AnyTag id={containerId}/>
}
```
`installViewer` is a convenience method that pulls in some dependencies that may `installViewer` is a convenience method that pulls in some dependencies that may
not be compatible with existing `react` apps. `@ohif/viewer` also exports `App` not be compatible with existing `react` apps. `@ohif/viewer` also exports `App`
which is a react component that takes the `configuration` outlined above as which is a react component that takes the `configuration` outlined above as
props. You can use it as a reusable component, and to avoid `react` version props. You can use it as a reusable component, and to avoid `react` version
conflict issues. conflict issues.
<!-- <!--
LINKS LINKS
--> -->