I'm getting an error of overload match but I didn't understand because isn't getting this error yesterday error in this happens too when I try to add another onClick function in another component or order page
code;
import React, { MouseEventHandler } from 'react'
import { Container, Image } from './styles'
interface ImageFullscreen {
path?: string
shown: boolean
close: MouseEventHandler
}
const ImageFullscreen: React.FC<ImageFullscreen> = ({
path = 'https://via.placeholder.com/1920x1080?text=Imagem Placeholder Das Postagens',
close,
shown,
}) => {
const handleMapViewClose: MouseEventHandler<HTMLDivElement> = e => {
const source = (e.target as HTMLDivElement & HTMLImageElement).src
if (source === undefined) {
close(e)
}
}
return (
<Container display={shown} onClick={handleMapViewClose}>
<Image src={path} alt='ImageFullscreen' />
</Container>
)
}
export default ImageFullscreen
code of container
import styled from 'styled-components'
import { fadeIn } from 'styles/keyframes'
interface Container {
display: boolean
}
export const Container = styled.div<Container>`
position: fixed;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.8);
top: 0;
left: 0;
z-index: 1000;
display: ${props => (props.display ? 'flex' : 'none')};
align-items: center;
justify-content: center;
padding: 50px;
animation: ${fadeIn} 500ms 1;
`
export const Image = styled.img`
max-height: 100%;
max-width: 100%;
min-height: 600px;
`
CodePudding user response:
I think you have a problem in the name of your interface, it's the same of your Component, maybe you can change the name and it will works.
something like this:
interface IContainer {
display: boolean
}
export const Container = styled.div<IContainer>`...`
CodePudding user response:
Lucas, if you try
const handleMapViewClose = ( e : React.MouseEvent<HTMLDivElement> ) => {
const source = (e.target as HTMLDivElement & HTMLImageElement).src
if (source === undefined) {
close(e)
}
}
Does it work?
I think you misspelled the event iterface name maybe?