Warning: failed prop type: invalid prop `source` supplied to `image`, expected one of type [number].

The warning message you are seeing is related to a prop type validation in React. The error is stating that the prop called “source” being supplied to the “image” component is of an invalid type. The expected type for the “source” prop is a number, but it seems to be passed as a different data type.

Here’s an example to better understand the issue:


    import React from "react";
    import PropTypes from "prop-types";
    
    function Image(props) {
      // Component logic here
    }
    
    Image.propTypes = {
      source: PropTypes.number.isRequired
    };
    
    function App() {
      return (
        <div>
          <Image source="image.jpg" /> // Invalid usage: string instead of number
        </div>
      );
    }
    
    export default App;
  

In the above example, the Image component expects the “source” prop to be a number, but we pass a string value “image.jpg” instead. This results in the warning you mentioned.

To resolve this issue, you should update the “source” prop to a number as expected by the Image component. For example:


    <Image source={123} /> // Corrected usage: number value
  

By passing a number value as the “source” prop, the warning should disappear.

Related Post

Leave a comment