Set redux state whenever website data is fetched

This commit is contained in:
Chris Walsh 2021-12-04 01:58:21 -08:00
parent fe861795bc
commit 9efd3eaa6a
No known key found for this signature in database
GPG key ID: 28EE0CCA6032019E
2 changed files with 16 additions and 2 deletions

View file

@ -1,4 +1,6 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { setWebsiteCreated } from 'redux/actions/websites';
import { FormattedMessage } from 'react-intl';
import Link from 'components/common/Link';
import WebsiteChart from 'components/metrics/WebsiteChart';
@ -11,9 +13,14 @@ import Chart from 'assets/chart-bar.svg';
import styles from './WebsiteList.module.css';
export default function WebsiteList({ userId }) {
const dispatch = useDispatch();
const { data } = useFetch('/api/websites', { params: { user_id: userId } });
const [hideCharts, setHideCharts] = useState(false);
useEffect(() => {
if (data) data.map(i => dispatch(setWebsiteCreated(i.website_id, i.created_at)));
}, [data]);
if (!data) {
return null;
}