import React, { useRef, useEffect } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import * as appPropTypes from './appPropTypes';
import * as stateActions from '../redux/stateActions';
const Notifications = ({ notifications, onClick }) => {
const chatwarpRef = useRef(null);
useEffect(() => {
if (chatwarpRef.current) {
chatwarpRef.current.scrollTop = chatwarpRef.current.scrollHeight;
}
}, [notifications]);
return (
聊天
{
notifications.map((notification) => (
{
notification.type === 'userMessage' ?
{
notification.isMe ?
:
<>
用户-{notification.id}
{notification.text}
>
}
:
{notification.text}
}
))
}
);
};
Notifications.propTypes = {
notifications: PropTypes.arrayOf(appPropTypes.Notification).isRequired,
onClick: PropTypes.func.isRequired
};
const mapStateToProps = (state) => {
const { notifications } = state;
return { notifications };
};
const mapDispatchToProps = (dispatch) => {
return {
onClick: (notificationId) => {
dispatch(stateActions.removeNotification(notificationId));
}
};
};
const NotificationsContainer = connect(
mapStateToProps,
mapDispatchToProps
)(Notifications);
export default NotificationsContainer;