mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 21:03:03 -05:00
Revert "feat: add answer for challenge 45"
This reverts commit 7458977d35.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
// import React from 'react';
|
||||
|
||||
export default function ReactPost(props: {
|
||||
title?: string,
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import { AfterViewInit, Component, ElementRef, EventEmitter, input, OnChanges, Output, ViewChild } from '@angular/core';
|
||||
import { createRoot, Root } from 'react-dom/client';
|
||||
import React from 'react';
|
||||
import ReactPost from './ReactPost';
|
||||
|
||||
type Post = { title: string; description: string, pictureLink: string };
|
||||
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: 'app-post',
|
||||
template: `
|
||||
<div #react></div>`,
|
||||
styles: ['']
|
||||
})
|
||||
export class PostComponent implements AfterViewInit, OnChanges {
|
||||
@ViewChild('react', { static: true }) containerRef!: ElementRef;
|
||||
|
||||
post = input<Post | undefined>(undefined);
|
||||
isSelected = input<boolean>(false);
|
||||
@Output() selectPost = new EventEmitter<void>();
|
||||
root?: Root;
|
||||
|
||||
ngOnChanges(): void {
|
||||
this.render();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.root = createRoot(this.containerRef.nativeElement);
|
||||
this.render();
|
||||
}
|
||||
|
||||
private render() {
|
||||
if (this.root) {
|
||||
this.root.render(
|
||||
<React.StrictMode>
|
||||
<ReactPost
|
||||
title={this.post()?.title}
|
||||
description={this.post()?.description}
|
||||
pictureLink={this.post()?.pictureLink}
|
||||
handleClick={() => this.selectPost.emit()}
|
||||
selected={this.isSelected()}
|
||||
/>
|
||||
</React.StrictMode>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user