I'd like to set the component's prop when the variable's value defined. Below is my current code.
import Cropper from 'react-easy-crop'
...
interface State {
...
coverFile: File | null;
...
}
class Test extends React.PureComponent<Props, State> {
state = {
...
coverFile: null,
...
};
...
const file = event.target.files;
self.setState({
coverFile: file[0],
});
<Cropper
image={coverFile?coverFile:undefined}
...
/>
And this is the error message.
No overload matches this call.
Overload 1 of 2, '(props: Readonly<CropperProps>): Cropper', gave the following error.
Type 'null | undefined' is not assignable to type 'string | undefined'.
Type 'null' is not assignable to type 'string | undefined'.
Overload 2 of 2, '(props: CropperProps, context?: any): Cropper', gave the following error.
Type 'null | undefined' is not assignable to type 'string | undefined'.ts(2769)
How can I solve this problem?
import Cropper from 'react-easy-crop'And this is image type:(JSX attribute) image?: string | undefinedimage={coverFile}Type 'null' is not assignable to type 'string | undefined'coverFile. That seems to be of importance