Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
heyajohnny opened this issue May 17, 2024 · 1 comment

Comments

@heyajohnny
Copy link

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
Copy link

evilDave commented Jul 9, 2024

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
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants