score:3
Accepted answer
new typings introduced to @types/react
in response to react 16.6 include the following types:
type componentprops<t extends keyof jsx.intrinsicelements | jsxelementconstructor<any>> =
t extends jsxelementconstructor<infer p>
? p
: t extends keyof jsx.intrinsicelements
? jsx.intrinsicelements[t]
: {};
type componentpropswithref<t extends elementtype> =
t extends componentclass<infer p>
? propswithoutref<p> & refattributes<instancetype<t>>
: propswithref<componentprops<t>>;
type componentpropswithoutref<t extends elementtype> = propswithoutref<componentprops<t>>;
which reference the types of a component's props. you should be able to achieve your desired interface using one of these new types:
interface formgroupprops {
label: string;
name: string;
component: react.componentprops<typeof component>;
}
this is super handy if you want to avoid exporting prop interfaces all over the place, or for extracting props interfaces from libraries which don't export them. also, unlike component['props']
, it also works for functional components.
Source: stackoverflow.com
Related Query
- React js: How to set props in JSX components which store in variable
- In how many ways we can pass props to all child components in react
- react how to pass props to inline css style in components
- How to deal with component reference variables and props in React 0.12+?
- How to pass props to children components in React
- React how to pass onSubmit handler through props to the components
- How to pass the props value from the other sibling components in React JS
- How to pass props in React Components correctly?
- How to test for types on react components and props
- How do I append values to the props of a react components children?
- How to sort react components based on props being passed into it
- How to get props from parent in React Styled Components
- How to pass (this) props to sibling components in React
- How to test react components props (expect component to be called with)
- React + TS, how to pass props from components A & B to components C, when props are slightly different and describe C props type?
- How to pass props to components in React js
- how to render React components with props from client
- How to pass props through a parent between two react components
- How to generate React components dynamically using an array of Props in TypeScript?
- How does react components use data without passing as props
- How to send props to state other components in React Hooks
- React - How to pass props down for the .map function when using functional components
- How can I pass props to React components conditionally?
- How do I establish default props for functional React components
- How to render props in react components while using react-router-dom version 6
- how to pass the data from data.json file in react components with the help of props in react js?
- How to send props to components via Link / Routes from react router dom?
- how to handle props between components in react
- Can't figure out how to pass props to components when using React Router v5 and Redux
- How to implement an props interface for conditions with styled components in React with Typescript
More Query from same tag
- How to place an image on the bottom left of a sidebar?
- Getting wrong clientHeight of a ref inside componentDidMount
- React: How to create different size input fields using antd?
- Reading data from Firebase 3 into a React component with ES6 syntax
- Can't set editorState in draft.js (it appears immutable but with no error)
- Mixed content error with videojs
- reactjs - fetch as google displays blank page only
- How to change the text color in TextInput?
- Destructuring in a React Class Component
- Extending component event handler props in React
- Open link in external window tab
- Data object with array of different groups, trying to display ordered by group type using .map() and pushing to new array nothing is rendering
- Why is React's concept of Virtual DOM said to be more performant than dirty model checking?
- How to dynamically create React elements (material-ui) with state expressions in property
- How to call a function from a function both residing on a React Component
- Acknowledge RabbitMQ message after socket IO event received from React browser
- How to hide a div and replace it with another div in reactjs?
- pass table row object from table and edit it using Redx-Form
- React-router-dom: How to update the props on a wrapper component?
- how generate options for select component dynamically with ant design
- Passing typescript props into styled components results in 'No overload matches this call' problem
- How to create a custom top navigation bar in React Native
- Read the setState value immediately after setting in useEffect React
- How to make first radio button selected by default in Material UI?
- How to extend ReactJS' Link component and show innerHtml
- apollo 2 a replacement for redux?
- Default React Component not rendering (Create-React-App)
- How to simplify this react-redux reducer state change
- Typeahead Text input not resetting after this.setState
- How to Initialize Materialize Dropdown Button in React?