Created
October 22, 2025 09:54
-
-
Save CharlieBreval12/c0772c40c4987784a65c2cd07bb0e7c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { ForwardedRef, forwardRef, MouseEvent } from 'react'; | |
| type ClickableListProps<T> = { | |
| items: T[]; | |
| onSelect: ( | |
| item: T, | |
| event: MouseEvent<HTMLButtonElement, globalThis.MouseEvent>, | |
| ) => void; | |
| }; | |
| function ClickableListInner<T>( | |
| props: ClickableListProps<T>, | |
| ref: ForwardedRef<HTMLUListElement>, | |
| ) { | |
| return ( | |
| <ul ref={ref}> | |
| {props.items.map((item, i) => ( | |
| <li key={i}> | |
| <> | |
| <button onClick={(e) => props.onSelect(item, e)}>Select</button> | |
| {item} | |
| </> | |
| </li> | |
| ))} | |
| </ul> | |
| ); | |
| } | |
| const ClickableList = forwardRef(ClickableListInner) as <T>( | |
| props: ClickableListProps<T> & { ref?: ForwardedRef<HTMLUListElement> }, | |
| ) => ReturnType<typeof ClickableListInner>; | |
| export default ClickableList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment