Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/add optional usePortal #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IAugmentedJQuery, IComponentOptions } from 'angular'
import fromPairs = require('lodash.frompairs')
import NgComponent from 'ngcomponent'
import * as React from 'react'
import { render, unmountComponentAtNode } from 'react-dom'
import { render,createPortal, unmountComponentAtNode } from 'react-dom'

/**
* Wraps a React component in Angular. Returns a new Angular component.
Expand All @@ -18,7 +18,8 @@ import { render, unmountComponentAtNode } from 'react-dom'
export function react2angular<Props>(
Class: React.ComponentType<Props>,
bindingNames: (keyof Props)[] | null = null,
injectNames: string[] = []
injectNames: string[] = [],
usePortal: boolean = false
): IComponentOptions {
const names = bindingNames
|| (Class.propTypes && Object.keys(Class.propTypes) as (keyof Props)[])
Expand All @@ -41,7 +42,8 @@ export function react2angular<Props>(
}
render() {
if (!this.isDestroyed) {
render(
usePortal ? createPortal(<Class {...this.props} {...this.injectedProps as any} />,
this.$element[0]) : render(
<Class {...this.props} {...this.injectedProps as any} />,
this.$element[0]
)
Expand Down