@bubblydoo/angular-react
Advanced tools
Comparing version 0.0.19 to 0.1.1
@@ -11,3 +11,3 @@ import * as ng from "@angular/core"; | ||
children?: any; | ||
} & React.RefAttributes<HTMLElement>>; | ||
} & React.RefAttributes<ng.ComponentRef<any>>>; | ||
export default _default; |
@@ -0,1 +1,2 @@ | ||
import { type ComponentRef } from '@angular/core'; | ||
import React from 'react'; | ||
@@ -9,3 +10,3 @@ declare const _default: React.ForwardRefExoticComponent<{ | ||
children?: any; | ||
} & React.RefAttributes<HTMLElement>>; | ||
} & React.RefAttributes<ComponentRef<any>>>; | ||
export default _default; |
{ | ||
"name": "@bubblydoo/angular-react", | ||
"version": "0.0.19", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "Hans Otto Wirtz <hansottowirtz@gmail.com>", |
@@ -124,2 +124,37 @@ # React in Angular and Angular in React | ||
### Refs | ||
You can get a ref to the Angular component instance as follows: | ||
```tsx | ||
import { ComponentRef } from '@angular/core'; | ||
const ref = useRef<ComponentRef<any>>(); | ||
<AngularWrapper ref={ref} />; | ||
``` | ||
To get a reference to the Angular component's HTML element, use `ref.location.nativeElement`. | ||
To forward a ref to a React component, you can simply use the props: | ||
```tsx | ||
const Message = forwardRef((props, ref) => { | ||
return <div ref={ref}>{props.message}</div>; | ||
}); | ||
@Component({ | ||
template: `<react-wrapper [component]="Message" [props]="{ ref, message }">` | ||
}) | ||
export class MessageComponent { | ||
Message = Message; | ||
message = 'hi!'; | ||
ref(div: HTMLElement) { | ||
div.innerHTML = 'hi from the callback ref!'; | ||
} | ||
} | ||
``` | ||
## Developing | ||
@@ -126,0 +161,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131534
897
191