score:0
Accepted answer
If you wish to pass a JSX element as a prop, you can use the type JSX.Element
, but you will also have to change Base
, since <Element/>
assumes Element
is a component, not an element. It works if you just return the element itself:
type BaseType = {
element: JSX.Element
}
const Base = ({ element }: BaseType ) => element
const renderBase = (element: JSX.Element) =>
<Base element={element} />
const Hello = () =>
renderBase(<h1>Hello</h1>)
(I've also renamed Element
to element
, to emphasize it's not a component.)
Source: stackoverflow.com
Related Query
- What is the correct way to set an element type passed as a parameter
- What is the correct way to type a React HOC?
- ReactJS: What is the correct way to set a state value as array?
- What Typescript type to set for setState passed to the component
- What is the correct way to set state in React
- What is the correct way to type a React component class that has no props?
- What is the correct way to set State according to fetch data?
- What does the error "JSX element type '...' does not have any construct or call signatures" mean?
- What is the correct way of adding a dependency to react in your package.json for a react component
- What is the cleanest way to remove an element from an immutable array in JS?
- Typescript/React what's the correct type of the parameter for onKeyPress?
- Typescript: What is the correct type for a Timeout?
- What is the correct type for React Click Event?
- ReactJS : What is the best way to give keys in array element
- What is the correct way to access props in the constructor?
- what is the correct type for a React instance of a component in typescript
- TS2322 Error when extending Button, component property not found. What is the correct way to type?
- What is the correct way to animate/transition between routes in react router
- What is the correct way to use inline style in react?
- What is the correct way to extend Material UI ListItem?
- What is the correct way of dispatching an action not tied to a component with Redux?
- What is the correct way to pass parameters to a React-query useQuery method that uses Axios
- 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?
- a11y: What is the correct `<track>` element for video chats?
- What is the correct way to add additional middleware through a redux store enhancer?
- Getting error "Cannot update a component while rendering a different component". What is the correct way to achieve what I'm attempting?
- What is the correct way to include SVG in ReactJS?
- What is the correct PropTypes for component or element
More Query from same tag
- React ref undefined
- Component path prop is matched but is not rendered using client-only route in Gatsby
- How does this React code translate to class representation?
- Pass this.refs as property in jsx in React.js
- How to use npm's 'events' module in Reactjs for eventEmitters
- How do you load React components asynchronously based on different server side states?
- How to secure my react app api with csurf?
- how to convert props content which has html tags html and display it instead of displaying it as string?
- Using webpack and React to load images
- How do I get the id of a button that was clicked? ReactJS
- React + TypeScript usage of className prop
- how can i access a variable globally in react js
- Add delay between two functions in reactjs
- Next.js background-image css property cant load the image
- Dynamically build routes using react-router
- Unhandled Rejection (TypeError): getNotes is not a function in react?
- Problems integrating P5 blob maker with React-P5 wrapper and as a graphics layer
- How to use React.js and Node.js on the same repository
- Add text over Image from Semantic UI
- React prop function called after useState set hook kills hook
- get param from url in react-router
- How to make FieldGroup type: file multiple react bootstrap
- useState not updating all components of my app
- Apollo client fetchMore from useQuery fires two network requests
- Which is better practice for setting state in react redux
- Transform object array to new array structure
- How to configure axios base URL?
- React useEffect executing last function
- React js - material ui - transfer list -- using old states
- How to implement onClick componentDidMount() in React using Axios