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

Warning/Error: CachedImage: Support for defaultProps will be removed #79

Open
ivanoikon opened this issue Apr 29, 2024 · 6 comments
Open

Comments

@ivanoikon
Copy link

After upgrade to RN 0.74.0 an error/warning is logged with react-native-image-cache 3.1.0

ERROR Warning: CachedImage: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.
in CachedImage (created by CGPItem)
in RCTView (created by View)
in View (created by Animated(View))
in Animated(View) (created by TouchableOpacity)
in TouchableOpacity (created by TouchableOpacity)
...

@SSenocico
Copy link

SSenocico commented May 14, 2024

The same.
How to fix it?

Screenshot 2024-05-21 at 14 55 46

@thecode7
Copy link

thecode7 commented May 16, 2024

Same issue here, we need fix or suggest patch.

@pehoracek
Copy link

I created and used patch for @georstat/[email protected]

diff --git a/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx b/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
index 9549160..df74a44 100644
--- a/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
+++ b/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
@@ -26,10 +26,6 @@ import { isAndroid, isImageWithRequire, isRemoteImage } from './helpers';
 const AnimatedImage = Animated.Image;
 const AnimatedView = Animated.View;
 
-const defaultProps = {
-  onError: () => {},
-};
-
 function useIsComponentMounted() {
   const isMounted = useRef(false);
   // @ts-ignore
@@ -58,7 +54,11 @@ function useStateIfMounted<S>(
   return [state, newSetState];
 }
 
-const CachedImage = (props: IProps & typeof defaultProps) => {
+interface CachedImagePropsWithError extends IProps{
+  onError?: () => void;
+}
+
+const CachedImage = (props: CachedImagePropsWithError) => {
   const [error, setError] = useStateIfMounted<boolean>(false);
   const [uri, setUri] = useStateIfMounted<string | undefined>(undefined);
   const { source: propsSource, options: propsOptions } = props;
@@ -291,6 +291,4 @@ const styles = StyleSheet.create({
   },
 });
 
-CachedImage.defaultProps = defaultProps;
-
 export default CachedImage;

@pehoracek
Copy link

It's actually been on PR for 2 months 272f205. Is this repo to be deprecated? Last commit is from 9 months ago...

@ivanoikon
Copy link
Author

Any news about this repository/package support? Is this repo to be deprecated?

@dlgchg
Copy link

dlgchg commented Dec 2, 2024

我创建并使用了@georstat/[email protected] 的补丁

diff --git a/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx b/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
index 9549160..df74a44 100644
--- a/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
+++ b/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
@@ -26,10 +26,6 @@ import { isAndroid, isImageWithRequire, isRemoteImage } from './helpers';
 const AnimatedImage = Animated.Image;
 const AnimatedView = Animated.View;
 
-const defaultProps = {
-  onError: () => {},
-};
-
 function useIsComponentMounted() {
   const isMounted = useRef(false);
   // @ts-ignore
@@ -58,7 +54,11 @@ function useStateIfMounted<S>(
   return [state, newSetState];
 }
 
-const CachedImage = (props: IProps & typeof defaultProps) => {
+interface CachedImagePropsWithError extends IProps{
+  onError?: () => void;
+}
+
+const CachedImage = (props: CachedImagePropsWithError) => {
   const [error, setError] = useStateIfMounted<boolean>(false);
   const [uri, setUri] = useStateIfMounted<string | undefined>(undefined);
   const { source: propsSource, options: propsOptions } = props;
@@ -291,6 +291,4 @@ const styles = StyleSheet.create({
   },
 });
 
-CachedImage.defaultProps = defaultProps;
-
 export default CachedImage;

nice, I used

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

5 participants