Created
August 29, 2022 14:12
-
-
Save NetanelBasal/9d7a883187f23abaf343210f2c440222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CommonModule } from '@angular/common'; | |
import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; | |
import type { ComponentProps } from 'react'; | |
@Component({ | |
standalone: true, | |
imports: [CommonModule, LazyReactComponentDirective], | |
template: ` | |
<h1>Todos page</h1> | |
<button (click)="showSelect = true">Show React Component</button> | |
<ng-container *ngIf="showSelect"> | |
<button (click)="changeProps()">Change</button> | |
<div [lazyReactComponent]="Select" [props]="selectProps"></div> | |
</ng-container> | |
` | |
}) | |
export class TodosPageComponent { | |
showSelect = false; | |
selectProps: ComponentProps<typeof import('react-select').default> = { | |
onChange(v) { | |
console.log(v) | |
}, | |
options: [ | |
{ value: 'chocolate', label: 'Chocolate' }, | |
{ value: 'strawberry', label: 'Strawberry' }, | |
{ value: 'vanilla', label: 'Vanilla' } | |
] | |
} | |
Select = () => import('react-select').then(m => m.default); | |
changeProps() { | |
this.selectProps = { | |
...this.selectProps, | |
options: [{ value: 'change', label: 'Change' }] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment