Sha256: f02803de9d2414dadf9580f9ec98bdf8ba2eb5d8816fd84f9704690abc2ddd23

Contents?: true

Size: 760 Bytes

Versions: 1

Compression:

Stored size: 760 Bytes

Contents

import React, { useEffect, useState } from "react";
import PropTypes from "prop-types";

import store from "stores/main";
import Article from "components/main/Article";
import ArticleModel from "models/Article";

function StatefulArticleList(props) {
  const [articles, setArticles] = useState(props.articles);

  useEffect(() => {
    const unsubscribe = store.subscribe(() =>
      setArticles(store.getState().articles)
    );

    return () => {
      unsubscribe();
    };
  });

  const list = articles.map(article => (
    <Article key={article.id} article={article} />
  ));

  return <>{list}</>;
}

StatefulArticleList.propTypes = {
  articles: PropTypes.arrayOf(PropTypes.instanceOf(ArticleModel)).isRequired
};

export default StatefulArticleList;

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
loco-rails-3.0.4 test/dummy/frontend/js/containers/main/pages/StatefulArticleList.js