In the parent file (NotificationParent) I get some data like this:
class Parent extends React.Component {
constructor(props) {
super(props);
this.state = {
notifications: []
}
}
componentDidMount() {
var self = this;
axios.get('url here').then(function (response) {
self.setState({
notifications: response.data
});
})
}
render() {
const notifications = this.state.notifications.map( (notification, i) => <NotificationCount key={i} {...notification} /> );
return (
<div>
{notifications}
</div>
)
}
}
ReactDOM.render(
<Parent />,
document.getElementById('notifications')
);
ReactDOM.render(
<NotificationTotal />,
document.getElementById('notificationcount')
);
In a second file (NotificationCount) I render this on the screen like:
render() {
return (
<li>
<a href="#">
{this.props.title}
</a>
</li>
)
}
In the third file (NotificationTotal) I'd like to show the amount of titles it has (example: 2):
export class NotificationTotal extends React.Component {
render() {
return (
<div>{amount goes here}</div>
)
}
}
In the third file (NotificationTotal) I can't get a amount because it does not know the props. How can I fix this?