Created
June 15, 2023 20:43
-
-
Save ernestlv/9e822a023b330e0dd9527ca81bcb5651 to your computer and use it in GitHub Desktop.
Simple React functional component with TypeScript annotations
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 React from 'react'; | |
interface SectionalProps { | |
title:string; | |
list:Array<{key:string, value:string}>; | |
onClick:( value: string ) => void; | |
} | |
export const Sectional:React.FC<SectionalProps> = ( { tile, list, onClick } ) => { //props is passed by react as an object | |
const onClickWrapper = ( e:any, value:string ) => { | |
e.preventDefault(); | |
onClick( value ); | |
} | |
console.log("rendering sectional..."); | |
return ( | |
<section className="container"> | |
<h2>{title}</h2> | |
<p>Click a pokemon name to see details:</p> | |
<ul className="listLink"> | |
{list.map(( item ) => { | |
const { key, value } = item; | |
return <li key={ key }><a href="#" onClick={ ( e ) => onClickWrapper( e, value ) }>{ value }</a></li>; | |
})} | |
</ul> | |
</section> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment