How do I fix this typescript error?

Joined
Sep 12, 2022
Messages
39
Reaction score
0
Type 'T' is not assignable to type 'ReactNode'.
Type '{}' is not assignable to type 'ReactNode'.
Type 'T' is not assignable to type 'ReactPortal'.
Type '{}' is missing the following properties from type 'ReactPortal': key, children, type, propsts(2322)
index.d.ts(1414, 9): The expected type comes from property 'children' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'

JavaScript:
export const List = <T extends {}>({ items, handleClick }: ListProps<T>) => {
  return (
    <div>
      <h2>List of items</h2>
      {items.map((item, index) => {
        return (
          <div key={index} onClick={() => handleClick(item)}>
            {item}
          </div>
        );
      })}
    </div>
  );
};

separate file

JavaScript:
interface ListProps<T> {
  items: T[];
  handleClick: (value: T) => void;
};

separate file

JavaScript:
import { Private } from "../components/auth/Private";
import { Profile } from "../components/auth/Profile";
import { Counter } from "../components/class/Counter";
import { List } from "../components/generics/List";
import { MutableRef } from "../components/ref/MutableRef";
import styles from "./styles.module.css";

const MoreHooks = () => {
  return (
    <div className={styles.main}>
      <MutableRef />
      <Counter message="kl" />
      <Private isLoggedIn={true} component={Profile} />
      <List items={[1, 2, 3]} handleClick={(item) => console.log(item)} />
      <List
        items={[
          {
            id: 1,
            first: "mk",
            last: "uid",
          },
          {
            id: 2,
            first: "mk",
            last: "uid",
          },
          {
            id: 3,
            first: "mk",
            last: "uid",
          },
        ]}
        handleClick={(item) => console.log(item)}
      />
    </div>
  );
};
export default MoreHooks;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,757
Messages
2,569,543
Members
45,026
Latest member
camilin05

Latest Threads

Top