I have a component right below which is later used inside another component in react.
Here is the code:
import React, { PropTypes } from 'react';
const MyComponent = () => (
<div>
<div className="row">
<div className="col-md-12">
<div className="media">
<div className="media-left media-middle">
<a href="#no"><img className="media-object" src={this.props.image} alt="" /></a>
</div>
<div className="media-body"><span className="pull-right">{this.props.name}</span>
<h4 className="media-heading">{this.props.title}</h4>
{this.props.desc}
</div>
</div>
</div>
</div>
</div>
);
MyComponent.propTypes = {
image: PropTypes.string,
name: PropTypes.string,
title: PropTypes.string,
desc: PropTypes.string,
};
export default MyComponent;
//Then on other component
import React from 'react';
import MyComponent from './mycomponent.component';
<MyComponent
title="Title Here"
name="Some Name"
desc="Description here"
image="http://placehold.it/100x100"
/>
The problem is that it's not rendering and the developer console is returning the following error:
"TypeError: undefined has no properties"
What is the problem here and how can I fix this issue?
You have to pass in props to MyComponent like so:
const MyComponent = (props) => (
console.log("example prop is", props.image);
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With