In your class component you should be extending or subclassing React.Component
and when you do, that means you are going to be overriding the constructor()
functions of React.Component
classes with the one from General
class-component, but you don't want to do that, you still want to access React.Component
constructor()
so you need to pass in props
to the constructor and to super()
.
Next, when passing state as props to a functional component, you need to pass in props
as an argument to the functional component, otherwise when doing this for example:
import React from 'react';
const ImageList = () => {
console.log(props.images);
return <div>ImageList</div>;
};
export default ImageList;
you will get that same error you got. Imagine I am trying to access state from your General
class-based component into this ImageList
component above and I do have it imported to General
, it will give me the same error, because I have not passed props
as an argument to ImageList
functional component.