score:6
Accepted answer
This should work:
import * as React from "react";
// In a more realistic example, there would be a more interesting relationship
// between the props types of the wrapped and resulting components.
function HOC(): <P>(Component: React.ComponentType<P>) => React.ComponentClass<{}> {
return function<P>(Component: React.ComponentType<P>): React.ComponentClass<{}> {
return class Bar extends React.Component<{}> {}
}
}
class Foo extends React.Component<{x: string},{}> {}
const Bar = HOC()(Foo);
// Get the instance type corresponding to the `Bar` constructor function,
// as you would have if you had just written `class Bar`.
type Bar = InstanceType<typeof Bar>;
class Test extends React.Component {
private ref: React.RefObject<Bar> = React.createRef<Bar>();
render(): any {
return (
<React.Fragment>
<Bar
ref={this.ref}
/>
</React.Fragment>
);
}
}
Source: stackoverflow.com
Related Query
- What is the correct way to type a React HOC?
- What is the correct way to type a React component class that has no props?
- What is the correct way of adding a dependency to react in your package.json for a react component
- What is the correct type for React Click Event?
- what is the correct type for a React instance of a component in typescript
- What is the correct way to animate/transition between routes in react router
- What is the correct way to change Navbar values in React based on if user is logged in?
- What is the correct way to define a React component's contextTypes in TypeScript?
- What is the correct typescript type for react children?
- What is the correct type to use for this React form field hook?
- React - what is the right way to sum the value of object by its type and then setState
- React - What is the correct way to make an API call with user input?
- What is the correct way to initiate a side-effect on page load when using React Strict Mode?
- What is the correct way to React Hook Fetch Api and store to Redux and retrieve it with Selector immediately?
- What is the correct way to include React in both an application and a private library? (React Invalid Hook Call warning from duplicate React)
- What is the correct way to update a counter in React
- What is the correct way to pass an argument to parent component in React from onClick event handler
- What is the correct way to set an element type passed as a parameter
- What is the correct way to use react hook useState update function?
- What is the correct way to set state in React
- What is the correct way to add to an array with splice in react
- What is the correct way to setup an independent Route that is not a part of App.js in React Router Dom?
- What is the correct way to collect data in react without Re-rendering and Perfomance Issues
- What is the correct way to handle an accesstoken with react to secure routes?
- What is the correct way to load prebuilt SQlite databases with or without PouchDB in a React App
- What is the correct way to recursively generate react elements?
- What is the correct way to loop through this array of objects inside of render, react
- What is the correct way to pass a function as a Prop in React
- What is the correct way to track which item is active in a tree, in react
- What is the correct way to correctly visualize a component React in top of another?
More Query from same tag
- Redux Form v6 - Generating dynamic form with unique keys loses focus on entering value
- How to use axios instance in different components in react?
- Keycloak - React.js cannot call API
- Passing data of a Child's form to Parent (App) in React
- You cannot render a <Router> inside another <Router>. You should never have more than one in your app
- How to stop react-spring looping animation
- Pass state from a JSX NavBar to a JSX Map in react
- Using <div> tag breaks the material UI Grid
- Handsontable not showing columns with missing data values
- how to set in one logic to render the component from given code
- Higher Order Component not firing wrapper render in ReactJS
- Problems Using New Firebase 9.0
- How to customize backgronud and color of tabs?
- How I can get the card id with onClick in react?
- How to properly write a wrapper for a React component?
- React js reset state of a component if the parent component has re-rendered
- Strongly typing the react-redux connect with typescript
- Material UI 3.9.3 Checkbox Styles not being set in IE
- Need help rendering ReactJS component - YouTube API
- Handler function doesn't have access to updated state variable
- How to send a image jpg/png file from react to express server
- Syntax error: Unexpected token (45:16) on handleChange in React JS
- Writing sanitizer function in Typescript to check for null, undefined and empty strings and getting error inside function
- Is it possible to map with multiple items?
- Build error occurred ReferenceError: describe is not defined > During now.sh deployment
- Uncaught TypeError: Cannot read properties of undefined (reading 'button')
- React-bootstrap navbar doesn't display correctly
- How to pass a state from a child to a parent in React?
- problem mixing material-ui elements and code in react javascript
- How to authenticate third party domain/origin and get access token