I'm using material-ui-icons v1.0.0-beta.36.
I'm trying to use a Search
icon in a .tsx component.
.tsx
component:
import React, { Component, ReactElement } from 'react'
import Search from 'material-ui-icons/Search'
import { Button, CustomInput } from '../thirdParty/CreativeTim/components'
import { ENTER_KEY_CODE } from '../../../Services/Constants'
import { SvgIconProps } from 'material-ui/SvgIcon'
let SearchIcon: ReactElement<SvgIconProps> = <Search />
Getting this error on the <Search />
component:
JSX element type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | Component<...> | null' is not a constructor function for JSX elements.
Type 'Component<SvgIconProps, any, any>' is not assignable to type 'Element | ElementClass | null'.
Type 'Component<SvgIconProps, any, any>' is not assignable to type 'ElementClass'.ts(2605)
Also, tried using it without assigning the variable:
.tsx
component:
import React, { Component, ReactElement } from 'react'
import Search from 'material-ui-icons/Search'
import { Button, CustomInput } from '../thirdParty/CreativeTim/components'
import { ENTER_KEY_CODE } from '../../../Services/Constants'
import { SvgIconProps } from 'material-ui/SvgIcon'
...
render() {
return (
<div>
...
<Button
onClick={this.onSearchclick}
color="white"
aria-label="edit"
justIcon
round
>
<Search />
</Button>
</div>
)
}
}
Getting kind of a same error on the <Search />
component:
JSX element type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | Component<...> | null' is not a constructor function for JSX elements.
Type 'Component<SvgIconProps, any, any>' is not assignable to type 'Element | ElementClass | null'.
Type 'Component<SvgIconProps, any, any>' is not assignable to type 'ElementClass'.
Types of property 'render' are incompatible.
Type '() => ReactNode' is not assignable to type '{ (): ReactNode; (): false | Element | null; }'.
Type 'ReactNode' is not assignable to type 'false | Element | null'.
Type 'undefined' is not assignable to type 'false | Element | null'.ts(2605)
Couldn't find anything online with a solution for that..
Any help would be appreciated.
I ended up solving that by declaring the icon with any
type:
const SearchIcon: any = Search
and then use it as a regular component:
<SearchIcon />