Sha256: 098788c194c4c1a5370444c282b8906b550fe2c5368be82efb30e4fce8ac0212
Contents?: true
Size: 1015 Bytes
Versions: 1
Compression:
Stored size: 1015 Bytes
Contents
import React, { useEffect, useState } from "react"; import PropTypes from "prop-types"; import store from "stores/main"; import { commentsForArticle } from "selectors/comments"; import Comment from "components/main/Comment"; import CommentModel from "models/article/Comment"; function StatefulCommentList(props) { const articleId = props.articleId; const [comments, setComments] = useState(props.comments); useEffect(() => { const unsubscribe = store.subscribe(() => { setComments(commentsForArticle(store.getState(), articleId)); }); return () => { unsubscribe(); }; }); const list = comments.map(comment => ( <Comment key={comment.id} comment={comment} /> )); if (comments.length === 0) { return <p id="no_comments">No comments.</p>; } return <>{list}</>; } StatefulCommentList.propTypes = { articleId: PropTypes.number.isRequired, comments: PropTypes.arrayOf(PropTypes.instanceOf(CommentModel)).isRequired }; export default StatefulCommentList;
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
loco-rails-3.0.4 | test/dummy/frontend/js/containers/main/articles/StatefulCommentList.js |