Revert "feat: add answer for challenge 45"

This reverts commit 7458977d35.
This commit is contained in:
Wandrille
2024-02-15 07:54:55 +01:00
parent 7458977d35
commit ebf6b135f8
6 changed files with 2 additions and 139 deletions

View File

@@ -1,4 +1,4 @@
import React from 'react';
// import React from 'react';
export default function ReactPost(props: {
title?: string,

View File

@@ -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>
);
}
}
}