React Components as TypeScript Generic Functions

React Components as TypeScript Generic Functions

React Components as TypeScript Generic Functions. Let’s say you want a component that will render a list of things. We could manually tell TypeScript that the object being passed to renderItem is a product and get proper typing. If you’re new to generics, well this post is probably a bad place to start.

Let’s say you want a component that will render a list of things. You want it to be flexible, to be able to render any sort of thing, like this:

<List
  items={products}
  renderItem={product => (
    <p>
      {product.name}: ${product.proice}
    </p>
  )}
/>

Or this:

<List
  items={notProducts}
  renderItem={notAProduct => (
    <p>
      {notAProduct.name}: {notAProduct.code}
    </p>
  )}
/>

development typescript react

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

Hire India's Best React JS Developers| Hire React JS Development Company

Looking to hire top dedicated Reactjs developers in India at affordable prices? Our 5+ years of average experienced Reactjs developers comprise proficiency in delivering the most complex and challenging web apps. Hire ReactJS development...

Hire Dedicated React Native Developer

Have you ever thought of having your own app that runs smoothly over multiple platforms? React Native is an open-source cross-platform mobile application framework which is a great option to create mobile apps for both Android and iOS. **[Hire...

Hire Dedicated React Native Developers - WebClues Infotech

WebClues Infotech is a expert in building iOS, Android Apps, Web apps , Websites, Enterprise solutions. We have crafted many complex and innovative projects that meets our customer expectations.

Hire Top React JS Developers | Offshore Reactjs Programmers India

description: Hire dedicated React JS developers & programmers in India for custom full-stack React JS projects on hourly/full-time basis. Strict NDA, 16+ years exp & 2500+ clients|450+ Experts