MABelanger / react-html5-camera-photo

HTML5 camera photo
https://www.npmjs.com/package/react-html5-camera-photo
MIT License
208 stars 94 forks source link

Support for defaultProps will be removed from function components in a future major release #144

Open heyajohnny opened 6 months ago

heyajohnny commented 6 months ago

Running on react 18.3.1 I get these errors:

Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.

According to AI, this should be the fix: Here’s an example of how you can transition from defaultProps to default parameters in a functional component:

// Before: using defaultProps
function Greeting({ name }) {
  return <div>Hello, {name}!</div>;
}

Greeting.defaultProps = {
  name: 'World',
};

// After: using default parameters
function Greeting({ name = 'World' }) {
  return <div>Hello, {name}!</div>;
}

Using default parameters simplifies the component and aligns with modern JavaScript practices. It’s a good idea to start refactoring your components to use default parameters if you haven’t already, to prepare for the upcoming changes in React.

evilDave commented 4 months ago

FYI: you can disable the warning for yourself (while waiting on someone to update the library) by adding this line after you import the Camera component:

Camera.defaultProps = undefined

NOTE: there is one defaultProp specified, isDisplayStartCameraError = true so you will probably want to set this to true when you instance the component eg:

<Camera
    idealFacingMode='environment'
    onTakePhoto = {(dataUri) => {
        handleTakePhoto(dataUri)
    }}
    isDisplayStartCameraError
/>
MABelanger commented 3 weeks ago

@heyajohnny, thank for opening this issue, the code will be updated.