Skip to content

Instantly share code, notes, and snippets.

@ernestlv
Created June 15, 2023 20:43
Show Gist options
  • Save ernestlv/9e822a023b330e0dd9527ca81bcb5651 to your computer and use it in GitHub Desktop.
Save ernestlv/9e822a023b330e0dd9527ca81bcb5651 to your computer and use it in GitHub Desktop.
Simple React functional component with TypeScript annotations
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