score:4
Accepted answer
You can make ParentComponent
generic as well so that the ChildComponent
can specify different props and state:
interface ParentProps {
something: string
}
interface ParentState {
somethingElse: string
}
export class ParentComponent<TProps extends ParentProps = ParentProps, TState extends ParentState = ParentState>
extends React.Component<TProps, TState> {
// Component Logic.
sharedFunction() {
// Some shared function.
}
}
interface ChildProps {
something: string
}
interface ChildState {
somethingElse: string
}
export class ChildComponent extends ParentComponent<ChildProps, ChildState> {
// Child component logic.
}
Source: stackoverflow.com
Related Query
- How to declare different state and props for subclasses on react with typescript
- How to specify (optional) default props with TypeScript for stateless, functional React components?
- how to type state and dispatch for useReducer - typescript and react
- router props and custom props with typescript react router dom for functional components
- how to use different IP address for development and production with react and axios
- React.render in TypeScript for component with both props and state
- How to define TypeScript types when used with React useState and the previous state inside a state updating function?
- How to setup a generic interface for the state when using React useReducer with typescript
- How to modify state in reduxjs/toolkit with React and TypeScript
- How to implement an props interface for conditions with styled components in React with Typescript
- relation between reactjs ,setState, Interface props and Interface state with respect to typescript , how can I use setState?
- How to declare a type for react thunk in typescript and reuse for component dependency?
- React & Jest, how to test changing state and checking for another component
- Typescript and React setting initial state with empty typed array
- How to set React component state and props from browser
- How to use React with Typescript and SASS
- How to correctly set initial state in React with Typescript without constructor?
- How to use React Context with useState hook to share state from different components?
- how to make webpack typescript react webpack-dev-server configuration for auto building and reloading page
- How to declare types of props of SVG component? [React, TypeScript and Webpack]
- React Typescript how send props and use it in child component
- How to use a different delay for each item with React transition group?
- Using different API url for development and production with React and axios
- ReactJS - How can I implement pagination for react with keep state when route change?
- Spread operator with React Props in Typescript (error: ...could be instantiated with a different subtype of constraint {})
- How to optimize React components with React.memo and useCallback when callbacks are changing state in the parent
- Sync queryParameters with Redux state and react router for function components
- How to TypeScript a props interface containing an object and merge with defaultProps
- How can ı pass function with state for react useContext
- how to change image src using props with styled component and react
More Query from same tag
- What does :: (double colon) mean in JavaScript?
- How do I set my Sidebar, Feed and Widgets side to side in my Twitter clone?
- Is it necessary for action creators to return an action ?
- Error: A required parameter (productId) was not provided as a string in getStaticPaths for /products/[productId]
- How can I pick a random border color in react?
- e.preventDefault() is not a function in Reactjs, bind used
- React: dynamic rendering of a component based on state
- React batch updates for multiple setState() calls inside useEffect hook
- Can't get value of a map index from a child copmonent to pass as function argument in React
- ReactJS: Perform a POST & GET request with a button
- How to change fontStyle and border color of VictoryTooltip
- How do I add select options from an object
- Map over array of objects and filter based on first name
- radio tabIndex to navigate using tab doesn't work in react
- Styled Components, required props defined as defaultProps show as missing
- react hooks - how to display one image of an array
- react snap and skipThirdPartyRequests
- Passing props to the makeStyle in TS
- Strange login flow examples in Redux-Saga documentation
- Adding an item to a list in React
- How to to access state variables or let,const,var variables of one component in other component in React.js?
- How to change the filtered date format in material table react?
- React JS: Image size flickers on reload with object-fit: cover CSS property
- TypeError: Cannot read properties of undefined (reading 'map') in react
- Cancelling previous async action using redux-thunk
- Abnormal behaviour of radio button when click
- React - Keep form information after getting a 401 response from API
- web.config rewrite rule not working in Azure static website in blob storage
- async await fetch api data in react
- React native view layer